Resolve IndexedDB adapter globals from globalThis instead of window - #554
Open
raphyabak wants to merge 2 commits into
Open
Resolve IndexedDB adapter globals from globalThis instead of window#554raphyabak wants to merge 2 commits into
raphyabak wants to merge 2 commits into
Conversation
Fixes nextapps-de#532. Document.search() with { merge: true } applies "limit" to each field's search independently, then merges the per-field results by unique id. When different fields match different, non-overlapping sets of ids, the merged total can exceed "limit" by up to (number of fields x limit), since nothing re-applies the cap after merging. Capture the overall requested limit before per-field options can override it, and stop merge_fields() once that many unique results have been collected.
Fixes nextapps-de#546. The IndexedDB persistent adapter resolved indexedDB/IDBTransaction/ IDBKeyRange only from window.*, guarded by typeof window !== "undefined". Inside a Web Worker there is no window object, even though IndexedDB is available there, so the guard short-circuits to false and the adapter fails with "IndexedDB.open is not a function". Read these from globalThis instead, which resolves correctly in the main thread, Web Workers, and Node.
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.
Summary
Fixes #546.
The IndexedDB persistent adapter resolves
indexedDB/IDBTransaction/IDBKeyRangeonly fromwindow.*, guarded bytypeof window !== "undefined":Inside a Web Worker there is no
windowobject, even thoughindexedDBis available there (viaself/globalThis). The guard short-circuits tofalse, and laterIndexedDB.open(...)throwsTypeError: IndexedDB.open is not a function(surfaces asBb.open is not a functionin the minified bundle, per the issue).Fix
Read these three globals from
globalThisinstead ofwindow.globalThisresolves correctly on the main thread, inside Web Workers, and in Node, so no environment-detection branching is needed.Test plan
test/db.indexeddb.js. Node has nowindowglobal either, which conveniently reproduces the exact broken precondition from the issue, so the test sets a fakeglobalThis.indexedDB, imports the adapter fresh, and asserts.open()calls through to it correctly.TypeError: IndexedDB.open is not a function— the exact error reported in the issue.npx mocha test/*.js --exit— 130 passing, 1 pending (pre-existing, unrelated).