FIX dexie storage: close Dexie connections and evict state cache on last close (#8793)#8797
Open
Cr4ftingMine wants to merge 2 commits into
Open
FIX dexie storage: close Dexie connections and evict state cache on last close (#8793)#8797Cr4ftingMine wants to merge 2 commits into
Cr4ftingMine wants to merge 2 commits into
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8793, as requested there, with a regression test based on
test/unit/bug-report.test.ts.The PR is structured in two commits so the reproduction stays verifiable:
DatabaseClosedError("Database has been closed").Test case
Reproduces the scenario from the issue: create a database with the dexie storage, close it, delete the underlying per-collection IndexedDB databases (like an application does on logout to remove user data from a shared device), then re-create the same database name in the same JS context. The test runs for the dexie storage only and returns early for other storages, since the defect is located in
dexie-helper.ts.Fix
Repairs the reference counting in
dexie-helper.ts:valueinstead of the still-unassignedstate(the factory callback runs synchronously inside the assignment, so the count was stored underundefinedandcloseDexieDb()computedundefined - 1 = NaN),getDexieDbWithTables()(there was no increment anywhere, so the close branch was unreachable),DEXIE_STATE_DB_BY_NAMEentry, otherwise the next open of the same name still receives the closed Dexie instance.Validation
npm run test:fast:dexie: 1404 passingnpm run check-types: cleanorga/changelog/