fix(storage): fall back to memory when IndexedDB is unavailable - #759
Open
erhnysr wants to merge 1 commit into
Open
fix(storage): fall back to memory when IndexedDB is unavailable#759erhnysr wants to merge 1 commit into
erhnysr wants to merge 1 commit into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@erhnysr is attempting to deploy a commit to the Tempo Team on Vercel. A member of the Team first needs to authorize it. |
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.
Problem
Storage.idb()guards onwindowbefore selecting IndexedDB-backed storage, but never checks forindexedDBitself. In a runtime that exposes a partialwindowwithout IndexedDB — React Native and Expo, some SSR setups —idb()is still chosen as the default, and the first read or write throwsReferenceError: indexedDB is not defined.The underlying cause is that idb-keyval treats an
undefinedstore as "use the default store", which opens IndexedDB unconditionally. So the existingtypeof indexedDB !== 'undefined'check inside the function never prevents anything — the delegation happens anyway.AGENTS.md:106 already calls this out as a rule:
This change brings the code into line with that rule rather than introducing a new policy.
Fix
Storage.idb()now falls back to the existing in-memory adapter when IndexedDB isn't available, instead of delegating to idb-keyval's default store.Putting the fallback inside
idb()fixes it at the root: all three default-storage call sites funnel through this function, so a partial-window runtime gets a working adapter — session persistence with structured-clone semantics viamemory()'smarkStructuredClone— rather than a startup crash. No changes toProvider.ts.Tests
src/core/Storage.test.tsassertstypeof indexedDB === 'undefined'as a precondition, then exercises set / get / remove throughidb(). Verified failing-first: before the change the firstsetItemthrows.Changeset
patch. No new API and no new capability for setups that already work — a crash becomes functioning degraded behaviour. This matches the bump used for the directly comparable guard fixes, #706 (crypto.randomUUIDguard) and #734 (partial-window announcement guard).Note on the trade-off
An app that previously crashed loudly at startup will now silently persist to memory instead, so persistence across reloads won't happen in that runtime. That's the same way the window-guarded defaults already degrade for SSR, and it's what the existing
indexedDBcheck was evidently meant to do.If you'd rather fail loudly — a clear
Error('Storage.idb requires IndexedDB')instead of degrading — that's a reasonable alternative, but it would leave the React Native default path crashing unless the three call sites also switch tomemory(). Happy to take it that direction if you prefer.