fix: tab-close cold-start wipes lastRealHost session store#14
Merged
Conversation
The onRemoved handler deleted from the in-memory Map and scheduled a persist
WITHOUT hydrating first. A tab close wakes a suspended SW: it cold-starts with
an empty Map, the handler deletes nothing, then the debounced persist writes {}
over chrome.storage.session — wiping all about:blank in-page-proxy attribution.
That is the exact failure P0.3 added persistence to prevent, now triggerable by
closing any tab instead of suspension alone.
Extract the logic into lib/last-real-host.js (mirrors the pin store) whose set()
and remove() hydrate before mutating, so no call site can clobber the store.
sw.js uses it for all reads, the nav write, and tab close. Add a regression test
in detect.mjs (faked session storage + injected timer) covering the cold-start
no-clobber invariant.
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.
Bug (found by Fable 5)
P0.3 persisted
lastRealHostto survive SW suspension, but theonRemovedhandler mutated + persisted without hydrating first. Sequence: SW asleep → student closes any tab → SW cold-starts with an empty Map → handler deletes nothing → the debounced persist writes{}overchrome.storage.session, wiping all about:blank in-page-proxy attribution. The exact failure P0.3 exists to prevent, now triggerable by closing a tab.Fix
Extract the logic into
extension/lib/last-real-host.js(mirrorscreatePinStore) whoseset()/remove()hydrate before mutating, so no call site can clobber the store.sw.jsuses it for all reads, the nav write, and tab close.Test
test/detect.mjsgains alast-real-hostsection with faked session storage + injected timer: a cold-startremove()must preserve stored attribution (fails against the old non-hydrating handler), the closed tab is still removed, andset()hydrates+merges+persists.Verified: full node suite, parity, pytest, eslint, prettier all green.