Description
In certain browser environments, the InstantDB client SDK throws a fatal ReferenceError: Can't find variable: indexedDB (or ReferenceError: indexedDB is not defined) during storage initialization, which completely crashes the client application.
Cause
In IndexedDBStorage.ts (specifically in @instantdb/core), the global indexedDB variable is referenced directly as a free variable:
const request = indexedDB.open(name);
and:
const request = indexedDB.open(this.dbName, 1);
In some browsers or restricted contexts (such as Safari private browsing, certain iOS embedded webviews, or environments with storage/cookies completely disabled), the indexedDB global variable is not defined on the global scope.
In JavaScript, accessing an undefined free variable throws a fatal ReferenceError, stopping code execution immediately.
Stack Trace
Here is the stack trace captured from production client-side error reporting:
@https://topicmatch.xyz/assets/index-DcJ47QhO.js:1:76970
Promise@[native code]
_init@https://topicmatch.xyz/assets/index-DcJ47QhO.js:1:76935
K0@https://topicmatch.xyz/assets/index-DcJ47QhO.js:1:76906
_initStorage@https://topicmatch.xyz/assets/index-DcJ47QhO.js:1:123427
L2@https://topicmatch.xyz/assets/index-DcJ47QhO.js:1:121721
fb@https://topicmatch.xyz/assets/index-DcJ47QhO.js:7:9342
oa@https://topicmatch.xyz/assets/index-DcJ47QhO.js:7:26894
Pf@
o6@https://topicmatch.xyz/assets/index-DcJ47QhO.js:16:6459
module code@https://topicmatch.xyz/assets/index-DcJ47QhO.js:196:102060
And the error message is:
ReferenceError: Can't find variable: indexedDB (or ReferenceError: indexedDB is not defined in Chrome).
Proposed Solution
Rather than referencing the free variable indexedDB directly, it should be accessed safely via globalThis or window, with a check for its existence:
const idb = typeof globalThis !== "undefined" ? globalThis.indexedDB : undefined;
If idb is undefined, the SDK could gracefully fall back to an in-memory/no-op storage provider, preventing the entire client application from crashing.
Description
In certain browser environments, the InstantDB client SDK throws a fatal
ReferenceError: Can't find variable: indexedDB(orReferenceError: indexedDB is not defined) during storage initialization, which completely crashes the client application.Cause
In
IndexedDBStorage.ts(specifically in@instantdb/core), the globalindexedDBvariable is referenced directly as a free variable:and:
In some browsers or restricted contexts (such as Safari private browsing, certain iOS embedded webviews, or environments with storage/cookies completely disabled), the
indexedDBglobal variable is not defined on the global scope.In JavaScript, accessing an undefined free variable throws a fatal
ReferenceError, stopping code execution immediately.Stack Trace
Here is the stack trace captured from production client-side error reporting:
And the error message is:
ReferenceError: Can't find variable: indexedDB(orReferenceError: indexedDB is not definedin Chrome).Proposed Solution
Rather than referencing the free variable
indexedDBdirectly, it should be accessed safely viaglobalThisorwindow, with a check for its existence:If
idbis undefined, the SDK could gracefully fall back to an in-memory/no-op storage provider, preventing the entire client application from crashing.