-
-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve Issue 1765 (application hang if requireAuth: true in Dexie Cl…
…oud) (#1766) * Resolves #1765 The `db` passed to db.on.ready() callback must not block until db is ready because the callback's code is part of making the db ready. A bug prevented liveQueries based on the unblocked db to emit values before on-ready callback resolves its promise. When using requireAuth: true, the entire authentication flow is done as a part of the on('ready') flow. A part of the flow was waiting for a liveQuery observable to emit currentUser value before continuing, leading to a deadlock. There was a general bug that the "_vip" state of the db wasn't propagated to transactions and tables. This is solved by letting the "_vip" version of the db (the one passed to on-ready callback) be a Proxy that makes sure to return vipped tables and transactions so that all code using that db instance will not deadlock before the on-ready callback completes. * Simplified arguments now that db._vip is a pure Proxy rather than a protype-derived object. * When error occur, a consequential error happened: postMessage failed to post an object with function properties. Make sure not to post the DexieError but a simpler one, copying the message only. * Let the "ResetDatabaseButton" reload the page to ensure application state reset. * One unit test fails. Must use Proxy instead of Object.create() for vipified tables / transactions. This will makes uses less complex, especially places where code is setting props on the vipified objects without having to get adjusted for the vip case. * Reverted unintentional code changes
- Loading branch information
1 parent
bf147d3
commit e96dd29
Showing
7 changed files
with
45 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { type Dexie } from "../classes/dexie"; | ||
import { type Table } from "../classes/table"; | ||
import { type Transaction } from "../classes/transaction"; | ||
|
||
export function vipify<T extends Table | Transaction>( | ||
target: T, | ||
vipDb: Dexie | ||
): T { | ||
return new Proxy(target, { | ||
get (target, prop, receiver) { | ||
// The "db" prop of the table or transaction is the only one we need to | ||
// override. The rest of the props can be accessed from the original | ||
// object. | ||
if (prop === 'db') return vipDb; | ||
return Reflect.get(target, prop, receiver); | ||
} | ||
}); | ||
} |