Repository navigation
Description
Context
Share intake reviews stashed shares under a native Web Lock per share id. A tab takes ownership with navigator.locks.request(name, { ifAvailable: true }, ...) and keeps the lock for as long as it reviews the share (holdShareReview, packages/ui-react/src/lib/share-review.ts:51-57).
To recover a share whose owning tab was terminated, every mounted intake rescans once a second (window.setInterval(() => void scan(), 1000), packages/ui-react/src/hooks/use-share-intake.ts:130). Each scan:
- lists the account's review partition;
- prunes and lists the share stash (
shareReviewIds,share-review.ts:88-93), where eachlistand prune opens and closes its own IndexedDB connection (withStore,packages/ui-sdk/src/client/share-store.ts:129-145); - tries an
ifAvailablelock for every id not already held.
On an installed app this runs for as long as the app is open, hidden or not, whether or not any share exists.
The polling was deliberate. It came with the share-original retention work in #1804 (PR #1899, commit fb219e069), and its comment states the reason: "A survivor recovers an owner abandoned by a terminated tab. Locks never expire under a slow upload or background suspension."
Web Locks already provide that recovery without polling. A request made without ifAvailable waits in the browser's queue and is granted when the holder releases the lock, including when the holding tab dies, and a queued request can be withdrawn with signal. New shares reach a tab through its own navigation (claimFromLocation, use-share-intake.ts:43-61), which runs on mount. A share that lands in another tab can be announced with a BroadcastChannel.
Guide: modern-web-guidance performance: "DON'T block the thread with recurring timers: Avoid heavy polling with setInterval that starves the main thread." Support (MDN BCD 8.1.6): LockManager.request is in Chrome for Android 69, Samsung Internet 10 and Firefox for Android 96; BroadcastChannel in 54, 6 and 38. A browser without navigator.locks already refuses review with a kept original (share-review.ts:52), and that does not change.
Recorded decision — 2026-10-22
The maintainer ruling selects a hybrid: queued Web Locks, account-scoped BroadcastChannel announcements and one safety rescan every 60 seconds only while visible. This replaces #1804’s one-second mechanism while preserving abandoned-share recovery. No mechanism choice remains.
Scope
Implement the ruled hybrid. Preserve native lock ownership for the entire review lifetime.
- On mount, and on each announcement, list the ids once. For each id this tab neither holds nor has queued, call
navigator.locks.request(name, { signal: lease }, cb)withoutifAvailable. The callback runs the existingrecoverShareReviewpath and returns at once if the share is gone. - After a successful stash claim or a review state change, post
{ type: "share-stashed" | "share-settled", id }on aBroadcastChannelnamed per account, and listen for it to queue or drop ids. WithoutBroadcastChannel, fall back to rescanning onvisibilitychangeto visible. - Prune the stash once per mount, once per announcement and once per safety pass, never once a second.
- Run the same idempotent list-and-queue safety pass every 60 seconds only while visible. Pause it when hidden; on visible run one immediate pass and resume. Skip held or already-queued ids.
- Remove the one-second interval. Clean up the safety timer and visibility/channel listeners; abort every queued request on unmount, root change or account change through the existing
lease/controllersignals. - Update the comment at
use-share-intake.ts:127-129.
Out of scope
- The share-target service-worker handler, the stash format and the 303 redirect.
- Review UI, confirm, dismiss, or upload behaviour.
- The IndexedDB connection-per-call pattern in
share-store.ts: with polling gone it is no longer hot, and pooling connections is a separate change. - Browsers without Web Locks.
Acceptance criteria
- The hybrid ruling is recorded and supersedes ui-react: share review admission deletes the durable original before confirmation #1804’s one-second recovery mechanism.
- Timer tests prove one safety pass at 60 seconds while visible, none while hidden, one immediate pass on becoming visible and no duplicate queued lock requests.
- With lock queueing disabled in a test double, the safety pass alone recovers an abandoned share within one interval.
- A real-browser test in the
share-reviewsuite (packages/ui-react/tests/browser/share-review/) shows that when tab A holds a share under review and is closed, tab B picks the share up without a reload. The test passes before and after the change, so recovery is preserved. - The same test shows that with no share stashed and both tabs idle for 10 s, no IndexedDB open happens after mount (counted by wrapping
indexedDB.open), where the tree before the change opens one or more per second. - A share stashed through tab A's navigation is queued in tab B through the broadcast, without a timer.
- After unmount, no lock request remains queued (
navigator.locks.query()shows none pending forbrain-ui:share-review:*). - Existing share intake tests (
packages/ui-react/tests/share-intake.test.ts, theshare-reviewbrowser suite) pass.
Verification
bun run test packages/ui-react/tests/share-intake.test.ts
bun run test:layout
bun run typecheck
bun run lintContract impact
- This touches the integration contract, so it needs the
contractlabel, aCONTRACT:commit prefix, and the doc updated in the same commit. - This changes a published package's behaviour, so it needs a changeset.
Not contract, and no changeset: recovery behaves the same, only the mechanism changes. Add a changeset if the ruling changes observable behaviour.
2026-10-22 triage at main aa8c8966b59f031f054f4876dbca84048b40ae4f: verified the still-active one-second interval and explicit abandoned-owner recovery comment. The proposed queued-lock/BroadcastChannel replacement and the alternative hidden-page pause remain a genuine mechanism choice; preserve needs: decision, p3 and native #2565 parent. No timer removal, lock-queue runtime proof or approved replacement is inferred.
2026-10-22 readiness reconciliation at inspected main aa8c896: folded the later maintainer ruling into the active specification and criteria. Earlier proposal/needs statements above describe their dated review stage. The accepted brief has no remaining needs prerequisite; add agent-ready. No implementation or runtime completion is claimed.
Activity
schlessera commentedon Oct 22, 2026
2026-10-22 triage at main
aa8c8966b59f031f054f4876dbca84048b40ae4f: verified the still-active one-second interval and explicit abandoned-owner recovery comment. The proposed queued-lock/BroadcastChannel replacement and the alternative hidden-page pause remain a genuine mechanism choice; preserve needs: decision, p3 and native #2565 parent. No timer removal, lock-queue runtime proof or approved replacement is inferred.schlessera commentedon Oct 22, 2026
Maintainer ruling
Hybrid. This replaces the 1-second rescan chosen in #1804 (PR #1899).
navigator.locks.request(name, { signal: lease }, cb)withoutifAvailable. The browser grants the lock when the owner releases it or its tab dies. The callback runsrecoverShareReviewand returns at once if the share is gone.BroadcastChannelper account. After a stash claim or a review state change, post{ type: "share-stashed" | "share-settled", id }. Listeners queue or drop ids accordingly. WithoutBroadcastChannel, rescan onvisibilitychangeto visible.hidden, resumes onvisiblewith one immediate pass, and stops on unmount, root change or account change. This is the belt-and-braces check in case a lock queue entry is ever lost.The 1 s
setIntervalis removed. Update the comment atuse-share-intake.ts:127-129to describe the three layers.Acceptance criteria adjustments
navigator.locks.query().indexedDB.openafter mount, because the safety pass runs at 60 s.No contract impact and no changeset: recovery behaves the same, only the mechanism changes.
schlessera commentedon Oct 22, 2026
2026-10-22 readiness reconciliation: folded the maintainer ruling into the body, replacing the unresolved-choice specification and aligning scope/criteria with the accepted branch. The remaining work is explicitly scoped; add agent-ready. Preserve priority, native parent, assignment and release attribution. This is issue preparation, not implementation, runtime proof or delivery.