Skip to content

fix(relay): keep a PC's details closed when a closed sheet's Back lands late - #4220

Merged
devswha merged 1 commit into
mainfrom
fix/sheet-late-step
Nov 19, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/sheet-late-step

Conversation

@devswha

@devswha devswha commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

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.tsx only:

  • While a closed sheet's Back is pending (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), navigateTo shows 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.
  • The first popstate settles the queue, whether a dashboard is mounted or not. If that popstate is the sheet's Back landing on the entry under the sheet's (matched by that entry's key), the queued addresses are pushed over it. The history then ends as it would with no race: details, then the list, nothing ahead. Back from the list opens the details again, and Forward closes them. A Back or Forward of the user's own that lands elsewhere wins, and the queue is dropped.
  • A dashboard mounted meanwhile (a sign-out, say) shows the held place.
  • Where the browser exposes no entries, nothing is held and the address is written at once, as before.
  • No timers, no new UI, no new wording, and no change to 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).

Finding Resolution
The user's own Back during the pending step was taken for the sheet's Fixed: the landing is told by the key of the entry under the sheet's; anything else is the user's own traversal and wins. Without the Navigation API nothing is held.
A remount lost the held close; a Back while no dashboard was mounted was undone Fixed: the queue is module state, settled by the first popstate whether a dashboard is mounted or not.
Two actions became one history entry Fixed: an ordered queue.
Opening a second sheet before landing hid the landing Fixed by matching the target entry's key, which a newer sheet entry does not change.
Regression gaps The unit test asserts the URL is unchanged before the landing; the browser regression asserts the event order at 1440 and that the first Escape closes only the sheet.
(a) Close a sheet, open and close Add a PC, then close the details, all before the first Back lands Accepted risk. Reproduced only with simulated traversal order. The lead asked for a check in a real browser in the CI runner image, scripted as fast as Playwright can drive it, 20 runs at 390 (CPU 6x) and 20 at 1440. In none of the 40 runs was the sheet's Back still pending at the last Escape, and the details never stayed open.
(b) A Back the browser drops with no popstate Accepted risk. Reproduced only with a simulated drop. While it holds, the dashboard makes no navigation that could drop the step.
The user picks, from Back history, exactly the details entry the sheet's Back targets, inside that window Accepted risk. It cannot be told apart from the sheet's own landing, and it ends on the list.

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's RelayDashboard.tsx; the sixth checks that, with no Navigation API, the address is written at once as on main.
    • The details stay closed when the sheet's Back lands on them. Before the landing the URL is unchanged and nothing is pushed; after it, exactly one push (/#pcs). The user's Back then opens the details again.
    • Places opened meanwhile are written in order (/#pcs, /#devices).
    • The user's own Back or Forward elsewhere wins, with no push.
    • A dashboard mounted before the landing keeps the held place.
    • A Back of the user's own while no dashboard is mounted wins.
    • Where the browser gives no entries, nothing is held.
  • scripts/sheet-history-late-step-regression.ts (new, listed in scripts/ci-browser.sh after relay-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.
    • On the phone, the page holds the sheet's history.back() until the second Escape has closed the details, then releases it onto the entry it named, as a slow browser would.
    • At both widths it asserts the event order and that the first Escape closes only the sheet.
    • Event-ordered, with no waits for time and no retries.

Validation

  • CI runner image on the remote heavy host (ovis-in-image, bun run build:shell):
    • The regression with main's RelayDashboard.tsx: FAIL late-step-390-cpu6x (the details came back, and the address never returned to #pcs).
    • The regression with this fix: 3 of 3 runs passed at both widths (escape back escape popstate; closed at #pcs, Back to #pcs?pc=…, Forward to #pcs at 390, and escape escape at 1440). Run on the earlier queue head; this head changes the hold condition and adds the first-Escape assertion.
    • The real-browser race check for case (a), described in the Review section: 0 of 40 runs reproduced.
  • bun run typecheck: clean.
  • bun test on src/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.ts and both conventions.test.ts: pass.
  • bun run check fast on the remote heavy host: green with bun 1.4.4, the version package.json pins (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.
  • Skipped: the full browser lane, WebKit and Firefox.

…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.
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a navigation issue on phones where closing PC details immediately after closing a sheet could leave the details open again when navigating Back.
    • Back and Forward now follow the expected history: Back can reopen PC details, and Forward returns to the list.

RelayDashboard now defers dashboard hash writes while a sheet Back is pending and settles them when the browser reports the traversal. New unit and Playwright regression tests cover this navigation sequence.

Changes: Sheet Back Navigation

Layer / File(s) Summary
Coordinate dashboard history
src/components/RelayDashboard.tsx, src/components/RelayDashboard.test.tsx
RelayDashboard queues dashboard hashes when it can identify the pending Back destination. On popstate, it writes the queued hashes only if the traversal reached that entry. Tests cover intervening navigation, Back and Forward to other entries, remounting, and the fallback without the Navigation API.
Validate late sheet Back navigation
scripts/sheet-history-late-step-regression.ts, scripts/ci-browser.sh, changelog.d/relay-details-late-sheet-back.md
The Playwright regression checks the delayed sheet Back scenario at 390px and 1440px. Browser CI runs the regression, and the changelog describes the phone behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related PRs

  • devswha/ovis#4194: This PR addresses the same ordering problem by holding address-bar writes until the sheet Back traversal is reported.

Suggested labels: bug

Merge Risk: Minimal · up to 97053

This change keeps a PC's details closed when a closed sheet's Back lands late. No concrete merge-blocking risk was found, and unit and browser regression tests cover the behavior. Cross-browser behavior outside Chromium was not run.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the primary change: a closed sheet's late Back no longer reopens a PC's details in the relay dashboard. It is specific, single-sentence, and matches the scope in the summary and object…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the template's two sections, Change and Validation. The Change section explains the race, the fix in RelayDashboard.tsx, and the accepted risks. The Validation section lists ty…
Full details: Title check

Explanation

The title names the primary change: a closed sheet's late Back no longer reopens a PC's details in the relay dashboard. It is specific, single-sentence, and matches the scope in the summary and objectives (RelayDashboard.tsx queue for pending sheet Back). It uses the conventional fix(relay) prefix and stays under typical length.

Full details: Description check

Explanation

The description follows the template's two sections, Change and Validation. The Change section explains the race, the fix in RelayDashboard.tsx, and the accepted risks. The Validation section lists typecheck, targeted bun tests, check fast on Bun 1.4.4, CI-runner regression runs, and the skipped browser lanes (WebKit and Firefox). It omits no required section. The changelog reference is not explicit, but the diff adds changelog.d/relay-details-late-sheet-back.md, so the template's changelog requirement is covered.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7a5fb93 and 9705307.

Files selected for processing: 5

  • changelog.d/relay-details-late-sheet-back.md
  • scripts/ci-browser.sh
  • scripts/sheet-history-late-step-regression.ts
  • src/components/RelayDashboard.test.tsx
  • src/components/RelayDashboard.tsx

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@devswha
devswha merged commit b3ff091 into main Nov 19, 2026
26 of 28 checks passed
@devswha

devswha commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Merged through pr-merge at head 9705307ad. Seen before the merge was asked for: required checks green, no unresolved thread, no conflict, no hold, main not red, no release in progress. CodeRabbit reviewed this head.

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.

@devswha
devswha deleted the fix/sheet-late-step branch November 19, 2026 09:15
devswha added a commit that referenced this pull request Nov 19, 2026
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant