Skip to content

fix(web): every right-panel file reopens where the reader stopped - #220

Merged
orbitingflea merged 2 commits into
mainfrom
fix/file-reading-position
Nov 19, 2026
Merged

orbitingflea merged 2 commits into
mainfrom
fix/file-reading-position

Conversation

@orbitingflea

Copy link
Copy Markdown
Owner

Every file the right panel shows now reopens where the reader stopped, after a right-panel tab switch or a page close, also after the file changed.

改了什么行为

Behaviour change: yes, a reader of any file in the right panel (workspace files and chat attachments, web and desktop) comes back to the place they left after a tab switch or a page close, and right-panel PDFs open in T3 Code's PDF viewer instead of the browser's own.

  • Covered: code, Markdown, PDFs, large text, CSV and TSV, HTML pages, Word, PowerPoint, the first sheet of Excel and ODS spreadsheets, notebooks, Mermaid, attachments; video and audio come back paused at the time left.
  • A place past the end of a changed file caps to its start or end. A link to a line still wins once.
  • Still at the top: image zoom, fonts, archives, SQLite, ODT, ODP, RTF, EPUB, HTML attachments, the other sheets of a spreadsheet. A place past notebook cell 20 opens at the end of cell 20.

Why

PR #163 kept the place only for code, rendered Markdown and PDF.js. Every other viewer started at the top, and the browser's own PDF viewer, the default on desktop Chrome and Edge, reloads at page 1 and cannot tell the page where the reader is.

How to undo

Revert the two commits. Saved places stay in the browser and expire after 30 days.

Design and checks
  • Places stay in this browser's local storage, keyed by environment and absolute path (attachments by attachment id), as in PR feat(fork): files reopen where the reader stopped #163. The newest sample wins, and a remount reads a sample that is not yet written.
  • New fork logic is in the fileReading* files: fileReadingPlace.ts finds and tracks each viewer's scroller, and fileReadingFrame.ts decides the HTML frame's restore and save. Upstream files get small hooks: a reveal line and a mount event for large text, tables and the first sheet, a width and a page cap for PDF.js, and the frame's message wiring.
  • The search for a viewer's scroller runs only while a saved place or a link to a line waits to be shown, and stops once it finds it.
  • Large text and tables restore by line or row through the viewer's own reveal, so they can land a few rows off the old pixel place.
  • The HTML frame restores the live place, saves only after the page takes it, waits once for a page without the scroll script, and saves nothing from a page the frame navigates to. A linked page that scrolls before its own load event can still save once under the first file.
  • A PDF over the PDF.js limits (50 MB or 2,000 pages) now shows its error with a retry, where the browser's viewer used to open it.
  • Checks: the browser tests for each viewer fail on main and pass; vp run check:changed passes. A real browser with its own PDF viewer on showed each covered type, attachments included, back at its place after a tab switch and after a page close.

orbitingflea and others added 2 commits November 19, 2026 11:18
Most of these cases fail on main because only code, rendered Markdown
and PDF.js remember where the reader stopped:

- CSV tables, large text, Word pages, notebooks, Mermaid diagrams and
  attachments, the first sheet of Excel and ODS files, audio, video,
  Markdown attachments and HTML pages save no place, so they reopen at
  the top.
- A large-text citation is never recorded as shown, so it jumps back on
  every visit.
- Desktop Chrome and Edge open a PDF in the browser's own viewer, which
  page script cannot read, so its place and its sideways pan are lost.
- The store has no attachment key, no offset or media views, no PDF
  width, no held samples that reads can see before they are written, and
  no order for this page's own samples.
- A PDF page removed by an edit restores to the top of the last page
  instead of the document's end.
- No module decides when an HTML frame restores a page and when it
  saves, and no viewer container looks for a scroller to restore.

The cases also cover input while a large file is still indexing, a
citation the reader leaves before indexing ends, a log that changes
while it is open, a file opened again while it shows, sheets other than
a workbook's first visible one, a workbook whose first stored sheet is
hidden, a cell link into a workbook's first sheet, the table and raw
views of a large CSV attachment, a page that grows after load without
scrolling, a revision that restores while the reader scrolls the page on
screen, a revision that loads before the reader first scrolls, playback
that moves on before a tab switch or stays paused while another browser
tab saves a newer time, a first press on a player before its source
loads, a press on an untouched video after its first-frame seek, a media
file that changes while open and a press on it while the new source
loads, a press on reopened paused playback whose time then reads a few
milliseconds off, a table that the viewer mounts again inside itself
long after any click, a table the reader scrolls while a cited line
waits for the raw view, a CSV attachment table scrolled past its saved
row, a Markdown attachment named like a PDF, an Excel first sheet that
shows again after no press, and a revision restored twice that keeps one
retry chain. Three cases check that the container watches a viewer only
while a place or a citation waits, stops at a workspace file's code
view, which keeps its own place, looks again only briefly after a press
on a control, and never searches PDF.js.

Two cases pass on main and guard rules the change keeps: a page without
the scroll script stalls the swap once, and a PDF without a reading key
keeps the browser's own viewer on its first URL until the file changes.

The panel cases share fileReadingTestKit.tsx and the module stand-ins in
fileReadingTestMocks.tsx, whose asset URL refresh keeps one function per
resource object, as the real hook does. The HTML frame and PDF reading
view cases, and the container's look, have their own files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code, Markdown and PDF.js kept the reader's place, but large text,
CSV/TSV, HTML, Word, PowerPoint, spreadsheets, notebooks, Mermaid, media
and the browser's own PDF viewer opened at the top after a right-panel
tab switch or a page close.

- The reading store keys attachments as well as paths, keeps the newest
  sample, orders this page's own samples by capture even when the clock
  steps back, and lets a mount read a sample that is not yet flushed.
- fileReadingPlace.ts saves and restores the viewer container's
  scrollers: office pages, notebook cells, rendered Markdown, Mermaid,
  attachment source views, and video and audio time, which it samples
  again when the reader leaves while it plays, and returns to when a
  changed file reloads in the same element. A press on a player counts
  even before its source loads, but a source still loading saves
  nothing. The time after the restore and the player's own first-frame
  seek is the baseline, so leaving playback within 10 ms of it saves
  nothing. It watches the viewer for a scroller only while a saved place
  or a citation waits for one, for up to 30 s, or for 2 s after a press
  on a button, which may switch a sheet or a mode, and stops once it
  places one or meets a workspace file's code view, which keeps its own
  place. HTML pages and PDF.js keep their own place, so it leaves them
  alone. Only a workbook's first visible sheet keeps a place, by the
  sheet position the viewers now mark. An Excel grid that a cell link
  opens shows the linked cell, not the saved place, and the reader's
  later scrolls on it still save. A file opened again while it shows,
  such as from a chat link, keeps the same visit, so its sheet, its
  playback and its rows stay as they are. An attachment's place follows
  the viewer its content type picks, as the panel does, not its name.
- Large text, CSV/TSV and ODS rows restore through the viewer's own
  reveal line, which the panel reads as a store; an attachment picks the
  table or the raw line by the mode it shows. Scrolling the mounted rows
  cancels it. Each rows viewer that mounts, such as a log that changed,
  an ODS sheet or an attachment's raw view, and each Excel grid, asks
  for its place itself, so a sheet that shows late still restores. A
  large-text citation stays until the raw rows show it, then becomes the
  file's saved line and counts as shown.
- Right-panel PDFs open in PDF.js, a place saved at another width lands
  on the same spot, and only the restore's own scroll event goes
  unsaved, so a sideways pan is kept.
- fileReadingFrame.ts decides, for each document in an HTML file's
  frame, when to restore and when to save. A report short of the restore
  never becomes the place, a page that grows after load is asked again
  for a second by one retry chain per document, one page's saving never
  covers the next, a page without the scroll script stalls the swap
  once, a page the frame navigates to saves and changes nothing, and a
  revision gets the live place before it is shown when the reader moved
  while it restored or first scrolled after it loaded.
  BrowserDocumentFrame posts, saves and reveals what it returns.
- A chat attachment builds its asset resource from its own fields, so a
  panel re-render, such as the one a scroll of its table causes, keeps
  its signed URL and loaded text, and its viewer stays mounted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XXL labels Nov 19, 2026
@github-actions

Copy link
Copy Markdown

This PR changes the test suite by +34 test cases (browser +27, unit +7, server 0).

New browser test files: apps/web/src/components/files/fileReadingFrame.browser.test.tsx, apps/web/src/components/files/fileReadingPlace.browser.test.tsx, apps/web/src/components/files/fileReadingViewers.browser.test.tsx.
Each browser test file costs CI seconds of module loading before its first test runs; a unit test costs milliseconds.

Keep tests that would fail for a real reason, and test logic below the UI where it can be. See Testing.

@github-actions

Copy link
Copy Markdown

Thread transfer impact

⚠️ The latest CI run did not produce a thread transfer result for b04964e.

This comment will update automatically after the next completed run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant