Skip to content

fix(phone): keep file previews on the selected pane's address - #4888

Merged
devswha merged 4 commits into
devswha:mainfrom
iyuzhang:fix/file-preview-history-entry
Nov 27, 2026
Merged

devswha merged 4 commits into
devswha:mainfrom
iyuzhang:fix/file-preview-history-entry

Conversation

@iyuzhang

@iyuzhang iyuzhang commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Change

When a phone sheet refuses Back and its return is dropped, opening a file now gives the new history entry the selected pane's URL. The earlier entry keeps its URL. The address bar reuses the entry IDs already tracked for browsers without the Navigation API.

Fixes #4400

Validation

The address-bar and sheet-history tests and the Chromium phone Back demo passed. The fast check built and typechecked successfully. With the host HTTP proxy cleared, two server assertions passed when rerun individually and two remote setup tests timed out on both this branch and unmodified main. The full integration suite was skipped.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: devswha/ovis
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: b7c0b04
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 00691f9d-354c-4653-aadb-90fc4e041d59

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • In browsers without the Navigation API, opening a file preview after a sheet blocks Back now uses the selected pane’s address. This keeps the preview’s browser-history entry aligned with the pane being viewed, so navigating between the sheet, pane, and preview reflects the correct address.

The address-bar logic now uses sheetHistoryEntryKey() to track refused sheet traversals. A regression test covers opening a file after a refused Back when the Navigation API is unavailable. The changelog records the file-preview address behavior.

Changes: Sheet address history

Layer / File(s) Summary
Track refused traversal keys
src/lib/sheetHistory.ts, src/lib/useAddressBar.ts, src/lib/useAddressBar.hook.test.ts, changelog.d/file-preview-history.md
sheetHistoryEntryKey() returns the current navigation entry key or undefined. useAddressBar uses it to compare and store refused-entry keys. The test checks the pane URL after refused Back and verifies that opening a file adds a URL entry with FILE_PREVIEW_KEY state when the Navigation API is unavailable. The changelog records the file-preview address behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • devswha/ovis#3786: Changes sheet history behavior when a sheet refuses Back, including without the Navigation API.
  • devswha/ovis#3761: Adds the phone sheet Back refusal behavior used in this history scenario.
  • devswha/ovis#3803: Updates refused-Back handling in the same sheet-history mechanism.

Suggested labels: bug

Suggested reviewers: devswha

Merge Risk: Minimal · previous review b7d22

Opening a file on a phone after a sheet refuses Back should now keep the earlier history entry's address and give the new entry the selected pane's address. No merge-blocking risk was found in the supplied changes.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #4400 requires the address bar to know which history entry it may write, so it does not replace another pane's entry after a refused or returned sheet Back. At head, useAddressBar.ts adds `ref… Provide the source or diff of src/lib/sheetHistory.ts and the useAddressBar diff, plus test results or added tests for src/lib/sheetHistory.skips.test.ts sections D1, E1, and E2 under the Navigation API. Show that scenario 2 (a persis…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: file previews now keep the selected pane's address. It matches the changelog, the code change in useAddressBar, and linked issue #4400. It uses the conventional fix(ph…
Out of Scope Changes check Passed The changes stay within the refused-entry overwrite area named by #4400. They are: the changelog entry; the sheetHistoryEntryKey() accessor in src/lib/sheetHistory.ts; the useAddressBar.ts chang…
Description check Passed The description follows the template's two sections, Change and Validation. The Change section states the problem (a phone sheet refuses Back and its return is dropped, so opening a file can overwrite…
Full details: Title check

Explanation

The title names the main change: file previews now keep the selected pane's address. It matches the changelog, the code change in useAddressBar, and linked issue #4400. It uses the conventional fix(phone) prefix and is specific.

Full details: Out of Scope Changes check

Explanation

The changes stay within the refused-entry overwrite area named by #4400. They are: the changelog entry; the sheetHistoryEntryKey() accessor in src/lib/sheetHistory.ts; the useAddressBar.ts change that replaces the removed entryKey() helper and adds the refused-entry hold; and a test in src/lib/useAddressBar.hook.test.ts for the no-Navigation-API file-open path. Each change supports the same guard, so none is unrelated. The PR description's file-preview framing is narrower than the issue, but that does not make any file out of scope.

Full details: Description check

Explanation

The description follows the template's two sections, Change and Validation. The Change section states the problem (a phone sheet refuses Back and its return is dropped, so opening a file can overwrite another pane's history URL), the resulting behavior (the new entry takes the selected pane's URL, the earlier entry keeps its URL), and links issue #4400. The Validation section lists the address-bar and sheet-history tests and the Chromium phone Back demo as passing, the fast check's build and typecheck as passing, and reports two timeouts on both this branch and main. It also states the full integration suite was skipped. The template's own HTML comment and wording are followed.

Full details: Linked Issues check

Explanation

Issue #4400 requires the address bar to know which history entry it may write, so it does not replace another pane's entry after a refused or returned sheet Back. At head, useAddressBar.ts adds refusedEntry (recorded in onPop when sheetSteppedOff() is true, with sheetHistoryEntryKey()). wouldOverwriteRefused holds the write effect while the current key matches the refused key and the refused link names another pane. This addresses the entryless-sheet case in part (scenario 1), and it follows the key-based approach the issue suggests. Several points cannot be established from the evidence available: (a) the PR description and changelog scope the fix to browsers without the Navigation API, while the issue's reproduction is on Chromium with the Navigation API; (b) the new test covers only the no-Navigation-API file-open path; (c) the evidence does not show tests for the issue's sections D1, E1, and E2 in src/lib/sheetHistory.skips.test.ts, or for scenario 2 (a persistent drawer that goes back more than one entry), so whether sheetSteppedOff() is true in that case is unverified; (d) sheetHistory.ts and the diff hunks were not readable (the diff tool reported missing blobs), so the sheet traversal semantics were not checked directly.

Resolution

Provide the source or diff of src/lib/sheetHistory.ts and the useAddressBar diff, plus test results or added tests for src/lib/sheetHistory.skips.test.ts sections D1, E1, and E2 under the Navigation API. Show that scenario 2 (a persistent sheet that goes back two entries onto another pane's entry) no longer writes the shown pane's URL onto that entry.

Finishing Touches

Generate unit tests (beta)

  • 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

  • Source mode: Auto
  • Repository: devswha/ovis
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 12e9a21
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 98153c83-0694-465f-88b4-ce7e5e8b1737
Commits

Reviewing files that changed from the base of the PR and between 12e9a21 and b7d22bd.

Files selected for processing: 4

  • changelog.d/file-preview-history.md
  • src/lib/sheetHistory.ts
  • src/lib/useAddressBar.hook.test.ts
  • src/lib/useAddressBar.ts

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

… on a keyless entry

A refused Back that lands on an entry from before the counted run records no key; the address bar then blocked every later write, including the file preview's new entry. Block only while the current entry's key matches the refused one. Run the counted-history test for both cases with a fresh sheetHistory copy each time, and scope the changelog to Chromium.
@devswha

devswha commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thanks @iyuzhang, this is a solid fix and the test pins it well: on main's code the new test fails, with this PR it passes.

Maintainer edits (pushed to your branch, no force push):

  • Merged the latest main.
  • e05dae5: an adversarial review found one remaining case. When the refused Back lands on an entry from before the counted run (for example an entry the browser made itself), that entry has no key, so the guard blocked every later write, including the file preview's new entry. The guard now blocks only while the current entry's key equals the refused one; an unknown key still counts as the same entry, so a keyless browser keeps the old protection.
  • The test now runs for both cases (entry made in this run, entry made before it) and imports a fresh sheetHistory copy each time, so it also passes under --rerun-each.
  • The changelog now says Chromium, since only Chromium without the Navigation API gets the counted fallback.

Checks: bun run check fast passed locally (typecheck, build, 29274 unit tests).

@devswha
devswha merged commit 778c55e into devswha:main Nov 27, 2026
16 checks passed
@devswha

devswha commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Merged through pr-merge at head ac7ee3b53. 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 said it did not review (a limit or a skip) since this head.

main had moved since the checks of e05dae5fa: pr-merge --update merged it in (b7c0b041e), and every required check was green at this head.

It waited in the merge queue behind #4880, whose change overlaps it, before it was updated.

External PR; reviews: omo gate CLEAR at 76d22f6 + Codex adversarial (gpt-6.2-sol-fast xhigh, one MEDIUM fixed); maintainer edits: merged main, e05dae5 lets a keyed entry take the file URL after a refusal on a keyless entry, test covers both cases with a fresh module, changelog scoped to Chromium. CodeRabbit did not review this head. Bug reproduced on main (new test fails on original code).

devswha added a commit that referenced this pull request Nov 27, 2026
…4906)

Plan step B5. Fixes #4393 and #4400 (their remaining paths), on top of
#4888 which merged meanwhile.

## Problem
On a phone, `useAddressBar` wrote the shown place with `replaceState`
onto whatever history entry the browser was on. A sheet's own traversal
(a Back it refused, a way back the browser dropped, a step that landed
unheard) can leave the history on another pane's entry with this pane
still shown, so a routine render could write pane B's address onto pane
A's entry. #4724 and #4888 guarded one case each (`refusedEntry`). Left
over:
- #4393: after a closed sheet's own Back landed with no event, the
user's next Back was taken for the sheet's step: the address moved to A
while the screen stayed on B.
- #4400 / Settings: a pane that took the place over under Settings, on
an entry a sheet had closed over, was never written to the address.

## Change
- **The address bar owns one entry, by key.** It remembers the key of
its own entry: the one it last wrote, or the one a Back/Forward the app
(or Settings) followed landed on, or the one the page just made (a
sheet's, a Settings page's, a file's). It writes only onto that entry,
or onto an entry whose address already names the pane shown; otherwise
the write is held until the next popstate or new entry. Settings is the
one exception: the entry Settings steps back onto as it closes is taken
at that moment only (and not when Settings was opened over an entry that
was not the address bar's own).
- Keys come from `sheetHistoryEntryKey()` (the Navigation API key, or
the `ovis:place` key `sheetHistory.ts` keeps where Chromium has no
Navigation API). `sheetHistory.ts` gains `onHistoryEntryMade` (with the
key of the entry it was made over), so an entry pushed by anyone (a file
opened over another pane's entry) is owned with its correct address,
also where the browser tells no key.
- A browser that tells no key at all treats every entry as one: a
sheet's own traversal drops ownership, and it comes back with a followed
Back, the app's own move, a new entry the page made, or the sheets'
"traversal over" signal.
- Removed: `refusedEntry`, `wouldOverwriteRefused`. Kept: the
`sheetTraversalPending()` hold and `onSheetTraversalOver` (a sheet's
underlying entry is also "owned", so they still keep a dialog's draft
off the entry under it, #4387), and the unread-popstate hold.
- #4393: `hear` in `sheetHistory.ts` treats a step as the sheet's own
only when it lands on the entry the step named (`stepOnto`); a landing
elsewhere is the user's Back. `stepOnto` comes from the Navigation API
or, without it in Chromium, from the `ovis:place` keys. An address write
held while such a step was on its way is made once the silent landing is
settled.
- No UI, HTTP or WS contract change.

## Tests (failing first)
New cases drive the **real** `useAddressBar` over the **real**
`sheetHistory` in the fake browser of
`src/lib/sheetHistory.skips.test.ts` (the hook's probe moved to
`src/lib/useAddressBar.fixture.ts`, shared with
`useAddressBar.hook.test.ts`):
| Case | On main before this PR | Here |
|---|---|---|
| D1, E1, E2 of the #4387 gate reviews (pane A's entry keeps A through
roster renders, owner close and rejection) | pass (since #4724); kept as
locks, each fails with the write guard turned off | pass |
| A jump from a drawer over B whose place was taken over on a dialog's
entry | pass; fails with ownership reset turned off | pass |
| Settings: the pane that took the place over under Settings is written,
also after a sheet closed over that entry | **fail** (address stays on
pane a) | pass |
| #4393: the user's Back right after a closed sheet's own Back landed
unheard | **fail** (screen stays on b) | pass |
| #4400: pane b's file on its new entry with no Navigation API |
**fail** (file entry keeps pane a) | pass |
| No key at all: the other pane's entry is kept | pass; fails with
no-key handling turned off | pass |
| #4888's two cases | pass (merged) | pass |

`settingsHistory.test.ts` now imports its own copy of the module: it
passed only when it was the first file to load it.

## Verification (head 628d026)
- `bun test src/lib/sheetHistory src/lib/useAddressBar
src/lib/settingsHistory src/lib/historyKeys`: 164 pass, 0 fail.
- `bun run check fast`: exit 0 (typecheck, build, unit 29660 pass / 0
fail).
- `scripts/phone-back-demo-regression.ts` on a demo build of this head:
**20 of 20** passed (4 at a time). `settings-pages-demo-regression.ts`
passes.
- Android emulator (Android 16 AVD, Chrome 133, the system's real Back
key and real taps over the demo): drawer; a move to another pane, a row
menu over the drawer, Back x3 back onto the first pane; a file from
Files closed by Back, then Files. After every step the address's pane
equals the pane shown; all steps passed in 2 of 2 runs (also 2 of 2 at
the first head).
- Follow-up filed for a pre-existing path found in review: #4907.
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.

Phone Back across panes that a sheet refuses or returns from can write the shown pane onto another pane's history entry

2 participants