Skip to content

fix(history): closing a file or a diff after a reload under a phone sheet goes back to the pane - #3115

Merged
devswha merged 2 commits into
mainfrom
fix/reload-file-copy
Nov 6, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/reload-file-copy

Conversation

@devswha

@devswha devswha commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Fixes #3101

What

On a phone, a sheet (the command palette, the ⋯ menu) is a history entry that copies the entry it opened over. On reload lib/sheetHistory.ts turned that entry into an ordinary one by dropping only the sheet's own mark. Over a plain file, the copy kept ovis:file-preview, so it read as a second entry of the file above the real one: closing the file (X) went back one entry, landed on the real file entry, and the viewer came back. A repository diff had the same problem.

#3095 already counts such a copy for the web panel: a copy of a page's entry is one more of the page's (ovis:web-panel-below), and Close page goes back past it. This PR applies the same rule to a file's and a diff's own entry:

  • overCopiedWebPanel becomes overCopiedEntry (lib/historyKeys.ts). A copy of an entry that holds ovis:file-preview or ovis:repo-diff now also gets the count, so the copy holds one more entry under it. A file's or a diff's copy counts only where the entry under it is still the one it copied: a reload, and an address an item changed on the sheet's entry. Forward onto a retired sheet entry keeps main's rule, which counts only the web panel's copies. After Back, another pane may have taken over the entry under it (review round).
  • closeFile already goes back 1 + below. closeDiff now does the same through backUnderCurrentEntry, in place of a single history.back(). If the browser refuses the traversal, the closing latch is released, as closeFile already does.
  • ovis:file-preview and ovis:repo-diff now live in historyKeys.ts with the other shared history keys, so sheetHistory can recognise them without importing the viewers.

Back still steps through the entries one at a time, as before (#3095).

Pushes already drop the count where needed: openFile pushes through withoutWebPanel, openDiff drops it, and a web page pushed from the palette sets it to 0. So a fresh entry pushed over a copy never inherits the count. A file or diff that replaces the copy's entry keeps the count, so it still closes past both entries.

Design

This follows the rule #3058/#3095 set, which a browser tab also follows: closing drops everything the overlay holds, while Back walks through it. Nothing changes on screen, and there is no new setting.

Validation

  • Failing first, on origin/main 72b8127:
    • scripts/files-documents-demo-regression.ts, phone branch, new step (Documents → a file as the popup viewer, palette over it, reload, Close file): closing the file after a reload under the palette goes back to the pane's entry (0), not 1. It passes with the fix at 390 light and dark, and the 1280 steps pass too.
    • src/lib/sheetHistory.test.ts, new test: a sheet's copy of a plain file's or a diff's entry that is kept over it counts one more under it, and a copy that Forward lands on after Back does not. Reverting either side of the change turns it red.
    • src/lib/useFilePanels.hook.test.ts, new test: a diff over a copy of its entry closes back to the pane. Without the change it traverses onto the diff's own entry. It passes with the change.
  • Unit: sheetHistory, useFilePanels*, repoDiff, useFileViewer, webPanel and settingsHistory tests pass (54 + 38). Running settingsHistory.test.ts in the same process as sheetHistory.test.ts fails 6 settings tests on origin/main as well, because the files interfere with each other. Each file passes on its own.
  • bun run typecheck: pass.
  • In the CI runner image (herdr-ci-runner:local, uid 1001): files-documents, files-panel, palette-local-page, web-panel-mobile, file-viewer-mobile, diff-find and diff-line-notes regressions pass, and so does repo-diff-browser-qa.ts (Back/Close/focus of the diff). phone-worktree-sheet-regression.ts times out waiting for a response on origin/main in the image too, because it needs an owned herdr pane. It is not affected by this change.
  • bun run check fast: pass (12585 unit tests, 0 fail; typecheck, build, generated files).
  • After the review round: bun run check fast passes again, and so do the files-documents and palette-local-page regressions.
  • Skipped: bun run check full (CI runs the integration and browser lanes).

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 72b8127 and 581c019.

Files selected for processing: 10

  • changelog.d/file-close-after-reload-under-sheet.md
  • docs/development.md
  • scripts/files-documents-demo-regression.ts
  • src/lib/historyKeys.ts
  • src/lib/repoDiff.ts
  • src/lib/sheetHistory.test.ts
  • src/lib/sheetHistory.ts
  • src/lib/useFilePanels.hook.test.ts
  • src/lib/useFileViewer.ts
  • src/lib/useRepoDiffViewer.ts
  • 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

…e entry under it may be another pane's by now
@devswha

devswha commented Nov 6, 2026

Copy link
Copy Markdown
Owner Author

Review round (omo CLEAR at 6d73cab; Codex gpt-6.1-terra xhigh, two MEDIUMs from code tracing):

  1. Forward onto a retired sheet copy got a stale count (fixed). A file open, palette opened and closed with Back, the docked file's entry then taken over by another pane, then Forward: the retired copy of the file's entry got a count of one, so closing the file skipped the pane under it. The entry under a retired copy can change after Back, so a file's or a diff's copy now counts only on the two paths where the entry under it is still the one it copied: a reload, and an address an item changed on the sheet's entry. Forward onto a retired copy keeps main's rule, which counts only the web panel's copies, as fix(web-panel): closing a docked file or a page after a reload goes back under every page entry #3095 does. A failing-first unit test covers both sides (sheetHistory.test.ts). Reverting either side turns it red.
  2. presentFile collapse after two reloads (not changed). A diff with two stacked sheet copies, then its popup file docked: the fixed go(-2) lands on the first copy, as it does on main, where the copies also exist. This change does not touch that step. It is the limit fix(web-panel): closing a docked file or a page after a reload goes back under every page entry #3095 already named ("presentFile / openDiffFile step back a fixed two entries"). It needs two reloads under a sheet over a diff, so it is LOW and gets no follow-up issue.

After the fix: bun run check fast passes, and so do the files-documents and palette-local-page regressions at 390/1280, light and dark.

@devswha

devswha commented Nov 6, 2026

Copy link
Copy Markdown
Owner Author

Targeted Codex check of 581c019 (fix round), two P2s, both left as on main:

  1. Forward onto a retired copy of a plain file's entry still leaves a second file entry. After Back closes a sheet over a file, Forward lands on the sheet's old entry, and Close then lands on the file's real entry. That is how origin/main behaves. Counting that copy (as the first commit did) skips a pane that took the file's entry over meanwhile, which is worse: closing then goes back too far. Without a fact telling whether the entry under the copy is still the one it copied, this PR keeps the milder behaviour. The issue's case, a reload with the sheet open, is fixed, because there the entry under the sheet's entry is always the one it copied.
  2. A docked file's entry that already holds the web panel's count is still counted on Forward. That is fix(web-panel): closing a docked file or a page after a reload goes back under every page entry #3095's rule on origin/main for web panel copies, and this PR does not change it.

Neither is introduced by this PR relative to origin/main, so neither gets a follow-up issue (LOW, not reproduced in a browser).

@devswha

devswha commented Nov 6, 2026

Copy link
Copy Markdown
Owner Author

Local merge gate (owner-approved): bun run check fast passed at this head, omo CLEAR at this head, Codex Terra xhigh no HIGH (round-1 stale Forward count fixed; round-2 items are main behaviour), threads resolved, merges cleanly; failing-first files-documents step + 2 unit tests; CI-image regressions pass (files-documents, files-panel, palette-local-page, web-panel-mobile, file-viewer-mobile, repo-diff-browser-qa, diff-find, diff-line-notes). Same rule as #3095 for file and diff sheet copies. Fixes #3101. Merged without waiting for GitHub CI.

@devswha
devswha merged commit 0101784 into main Nov 6, 2026
10 of 13 checks passed
@devswha
devswha deleted the fix/reload-file-copy branch November 6, 2026 03:26
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.

A reload with the palette open over a file leaves a copy of the file's entry: closing the file shows it again

1 participant