fix: lazy-load storage cache on set() to prevent null spread#38
Merged
BitHighlander merged 1 commit intodevelopfrom Apr 20, 2026
Merged
fix: lazy-load storage cache on set() to prevent null spread#38BitHighlander merged 1 commit intodevelopfrom
BitHighlander merged 1 commit intodevelopfrom
Conversation
When an MV3 service worker wakes up and calls set() with an updater (e.g. requestStorage.addEvent spreading prev into a new array), the in-memory cache may still be null because _getDataFromStorage() is async. The updater then runs with prev = null and [...null] throws "TypeError: a is not iterable", aborting addEvent and leaving the approval flow in a bad state (popup opens for a request that was never persisted). Load the cache synchronously-ish (await from chrome.storage) in set() if it's still null, so every updater receives a real value. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
TypeError: a is not iterablethrown fromcustomStorage.addEvent(and any other storage updater that spreadsprev) when the MV3 service worker wakes up and callsset(...)before the async initial load ofcacheresolves.eth_signTypedData_v4:requestStorage.addEventfailed, but the ethereum handler continued torequireApproval(...)anyway — popup opened for a request that was never persisted, and the signing flow hung in a bad state.Root cause
packages/storage/lib/base.tsinitializescachetonulland populates it via a fire-and-forget_getDataFromStorage().then(...). In MV3 service workers that get torn down frequently,set()can be called before that promise resolves. The updater then runs withprev = null, and[...null, event]throws.Fix
In
set(), ifcache === null, await_getDataFromStorage()first so the updater always receives a real value (the on-disk value or the configured fallback).Test plan
eth_signTypedData_v4on a dapp, confirm the approval popup shows the request (noTypeErrorin background console).eth_sendTransaction/personal_signflows still populaterequestStorage→ approval → completed.🤖 Generated with Claude Code