Repository navigation
fix(relay): keep a PC's details closed when a closed sheet's Back lands late - #4220
Conversation
…ds late On a phone, the hosted app's dashboard pushed the list's address while a sheet's own history.back() (sheetHistory) was still on its way. That Back then landed on the details' entry under the list's, and the dashboard followed it, opening the details again. While sheetBackPending(), and where the browser tells its entries (the Navigation API), the dashboard now shows each place at once and holds its address writes, in order, outside the component (a dashboard mounted meanwhile shows them). The first popstate settles them, mounted or not: the sheet's Back landing on the entry under the sheet's, told by its key, pushes them over it; a Back or Forward of the user's own elsewhere wins and drops them. Where the browser tells no entries nothing is held, as before. Adds the browser regression sheet-history-late-step-regression.ts to the browser lane.
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
|
Merged through Reviews: omo (dori review) CLEAR at 9705307; Codex gpt-6.2-sol-fast adversarial review, 4 rounds on this change (the same diff before the rebase): every finding fixed or accepted. Accepted risks, simulated timing only: (a) three actions before a sheet's Back lands, (b) a Back the browser drops with no popstate, and the user picking exactly the targeted entry from Back history; tracked in #4221. On the lead's word, (a) was checked in a real browser in the CI runner image (40 runs at 390 CPU 6x and 1440): not reproduced, so merge. CodeRabbit reviewed this head. CI's one failure was an unrelated flake (reply-comments-demo-regression.ts), green on rerun. |
…efore a sheet Back lands (#4243) Fixes #4221 (race 1, which reproduces in a real browser; races 2 and 3 did not reproduce, and the evidence is on the issue). ## What was wrong In the hosted app's dashboard on a phone, the details of a PC could open again by themselves. The steps: 1. Close a sheet opened from a PC's details. 2. Before that sheet's `history.back()` lands, open Add a PC and close it. 3. Close the details. #4220 holds the dashboard's address writes while a closed sheet's Back is on its way, and settles them at the first popstate. It decided whether that popstate was the sheet's own landing by reading the browser's entries when the hold began. Add a PC's own entry had moved those entries, so the sheet's landing looked like the user's own traversal. The held `#pcs` was dropped, and the details opened again. It reproduced in Chromium 153 in the CI runner image at 390 px with CPU 6x in 5 of 24 runs, and in local Chrome 156 in 9 of 20. It never reproduced at 1440 px, where no sheet makes a history entry. ## What changed - `src/lib/sheetHistory.ts`: - Every `history.back()` the sheets take goes through one function. Where the browser exposes its entries (the Navigation API), that function records the key of the entry the step will land on. - `sheetBackOnto()` returns that key while the step is on its way, and `sheetBackLanded(event)` says whether a popstate is that landing. - A sheet that opened over the entry the step leaves, and closed before the step landed, takes no second step there. The one step leaves its entry too, and a second step would land one entry too far. - `src/components/RelayDashboard.tsx`: the held queue holds only while `sheetBackOnto()` names an entry, and settles on `sheetBackLanded(event)` instead of its own reading of the entries. - Browsers without the Navigation API keep main's behaviour: nothing is held, and every sheet takes its own step. No new text and no new screen. ## Validation - `scripts/sheet-history-late-step-regression.ts` gains the race-1 walk (Add a PC opened and closed between the two Escapes) at 390 and 1440. In the CI runner image, `late-step-add-pc-390-cpu6x` fails on main's sources (the address never returns to `#pcs`) and the walk passes here 4/4. - Race-1 driver (local Chrome 156): | Width | Before | After | |---|---|---| | 390 px, CPU 6x | 9/20 | 0/40 (12 runs still had the Back pending at the last Escape) | | 1440 | 0/20 | 0/20 | - Browser regressions that use sheets, in the CI runner image: `file-viewer-regression` PASS, `inbox-mode-demo-regression` PASS, `mobile-tabs-regression` PASS. - Unit tests: `sheetHistory.test.ts`, `sheetHistory.skips.test.ts`, `RelayDashboard.test.tsx` and `AgentSidebar.test.tsx`, 124 pass. The new `sheetHistory` test fails if either the landing check or the second-step skip is removed. - `bun run check fast` on old-desktop: exit 0. - Not run: WebKit and Firefox, and the full browser lane (CI runs it).
What was wrong
In the hosted app's dashboard on a phone, close a sheet opened from a PC's details (Escape or Back), then close the details straight away. The details could open again.
The sheet leaves its own history entry with
history.back()(src/lib/sheetHistory.ts). That traversal lands a moment later, on the entry it named when it was asked: the details' entry. If the second Escape came first, the dashboard had already pushed the list's address (#pcs). The late step then landed on the details' entry under the list's. The dashboard's popstate/hashchange sync followed that address and opened the details again.What changed
src/components/RelayDashboard.tsxonly:sheetBackPending(), added in fix(phone): keep the pane a sheet's Back would otherwise undo #4194), and where the browser exposes its history entries (the Navigation API),navigateToshows the new place at once but holds its address write. Every place opened in that window is queued in order, so Back later goes through each one.sheetHistory.ts. This extends the address bar's pattern from fix(phone): keep the pane a sheet's Back would otherwise undo #4194 to a queue.This replaces the earlier private attempt, which replayed navigations inside
sheetHistory.ts. Review blocked it because it changed every history writer while a step was pending. This fix stays in the one component that showed the bug.Design reference: browsers let the newest navigation win over an older pending traversal. The dashboard keeps that order by writing its navigations after the traversal lands.
Review
Four rounds of Codex (Sol Fast). Every finding below is fixed, except the three rows marked as accepted risks (simulated timing only).
Follow-up issue: #4221. It records the three accepted risks and their simulated reproductions.
Tests
src/components/RelayDashboard.test.tsx, six new cases under "a closed sheet's Back still on its way". The test window gives a Navigation API with entry keys. Five of the six fail with main'sRelayDashboard.tsx; the sixth checks that, with no Navigation API, the address is written at once as on main./#pcs). The user's Back then opens the details again./#pcs,/#devices).scripts/sheet-history-late-step-regression.ts(new, listed inscripts/ci-browser.shafterrelay-dashboard-browser-qa.ts) runs the hosted shell with the in-memory account service and a fixture directory, at 390 (phone, CPU 6x) and 1440.history.back()until the second Escape has closed the details, then releases it onto the entry it named, as a slow browser would.Validation
ovis-in-image,bun run build:shell):RelayDashboard.tsx:FAIL late-step-390-cpu6x(the details came back, and the address never returned to#pcs).escape back escape popstate; closed at #pcs, Back to #pcs?pc=…, Forward to #pcsat 390, andescape escapeat 1440). Run on the earlier queue head; this head changes the hold condition and adds the first-Escape assertion.bun run typecheck: clean.bun testonsrc/components/RelayDashboard.test.tsx(20 pass),src/lib/sheetHistory.test.ts,src/lib/sheetHistory.skips.test.ts,scripts/ci-browser.test.ts,scripts/changelog-fold.test.tsand bothconventions.test.ts: pass.bun run check faston the remote heavy host: green with bun 1.4.4, the versionpackage.jsonpins (unit: 19,255 pass, 0 fail). The heavy host's own bun 1.4.2 fails one unrelated test,src/lib/useAddressBar.hook.test.ts, on main too; it passes on 1.4.4 and in CI.