Skip to content

fix(web): a PDF page that mounts during a resize waits to paint - #41605

Open
Anton-M-R wants to merge 2 commits into
pingdotgg:mainfrom
Anton-M-R:fix/pdf-no-paint-during-resize
Open

Anton-M-R wants to merge 2 commits into
pingdotgg:mainfrom
Anton-M-R:fix/pdf-no-paint-during-resize

Conversation

@Anton-M-R

Copy link
Copy Markdown
Contributor

Problem

Resizing the file pane with a PDF open still drops frames after #41537. With a PDF of charts and images, a 6 second drag has 4 to 5 late frames and stalls of up to 67 ms.

To reproduce: open a PDF with heavy pages in the desktop app, scroll down a few pages, and drag the pane divider.

A page that has painted waits 150 ms for the width to settle before it paints again. A page that mounts during the drag has not painted, so it does not wait. It starts a pdf.js render on the main thread at once, and every later width change cancels and restarts that render.

Change

PdfViewer records the time of each change of the pane width. A page that mounts within 150 ms of one now waits the same 150 ms as the painted pages. Page loads at other times, such as the first open and scrolling, are not delayed.

Scope

This is a bug fix for a performance problem in one component: 19 changed lines outside tests. There is no issue for it. It is the second cause that I named under "Not checked" in #41537.

Verification

I found this in daily use of the desktop app on a 120 Hz MacBook display, where the resize was smoother after #41537 but not smooth.

Test. The new browser test narrows the pane once, which brings page 4 into the mounted range. On main it fails, because the viewer asks pdf.js for page 4 in the same commit as the resize. With the fix, page 4 is mounted but not requested, and it paints at the final width after the wait.

Measurement. I built apps/web from main (7182abe) and from this branch and mounted PdfViewer from each build in Chrome (GPU on, 60 Hz, device pixel ratio 2). The PDF has 12 pages with charts and images and starts on page 5. A script changed the pane width on every frame for 6 seconds. Each row shows two runs.

Drag Build Page renders started in the drag Frames over 20 ms Worst frame
480 to 740 px main 4 / 4 4 / 4 33 / 50 ms
480 to 740 px this PR 0 / 0 0 / 0 17 / 17 ms
760 to 1300 px main 12 / 12 5 / 4 67 / 67 ms
760 to 1300 px this PR 0 / 0 0 / 0 17 / 17 ms

Not fixed. A drag that pauses for more than 150 ms repaints the mounted pages at that pause, on main and with this PR. With a pause of 220 ms after every 20 frames, both builds started 40 renders. The late frames were 3 per drag on main and 1 per drag with this PR.

Desktop app. I ran the desktop dev build of this branch on the 120 Hz MacBook display and dragged the pane divider with a PDF open. The resize is smooth, about as smooth as the Word preview.

Not checked. I did not measure frame times at 120 Hz. There is no recording, because a screen capture does not show single late frames.

Claude Fable 5.2 with the Claude Agent SDK in T3 Code.

🤖 Generated with Claude Code

A page that entered the mounted range during a drag started a pdf.js
render at once, and every later width change cancelled and restarted it.
Only pages that had painted before waited for the width to settle.

The viewer now records the time of each width change, and a page that
mounts within 150 ms of one waits like the painted pages do.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 23, 2026
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ba883c0 and be07d6b.

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.

Walkthrough

The PDF viewer records viewport-width changes and passes the latest resize time to its pages. Pages wait before requesting PDF data when a resize occurred within the previous 150 ms. A browser test checks page loading and canvas width after a resize.

Changes: PDF resize rendering

Layer / File(s) Summary
Track and pass viewport resize time
apps/web/src/components/files/PdfViewer.tsx
The resize observer records when clientWidth changes. PdfViewer passes the resize timestamp to each PdfPage.
Delay page requests after resize
apps/web/src/components/files/PdfViewer.tsx, apps/web/src/components/files/PdfViewer.browser.test.tsx
PdfPage delays rendering after a recent resize, including for pages not yet painted. The browser test checks that a newly mounted page is not requested before the resize settles and that its canvas uses the settled width.

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

Change: Bug fix

Possibly related PRs

  • pingdotgg/t3code#39105: Adds the existing 150 ms wait for pages that have already painted; this change extends the wait to pages that mount during a resize.

Suggested reviewers: juliusmarminge, macroscopeapp

Merge Risk: Minimal · previous review ba883

This change makes PDF pages that mount during a pane resize wait for the width to settle before rendering, which reduces repeated renders during a drag. Initial open and scrolling are not delayed. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a PDF page that mounts during a pane resize now waits before painting, which matches the PdfViewer change that delays such pages by 150 ms. It uses the conventional co…
Description check Passed The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section explains the frame drops and the reproduction steps. The Change section explains the 150 ms…
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.
Full details: Title check

Explanation

The title names the main change: a PDF page that mounts during a pane resize now waits before painting, which matches the PdfViewer change that delays such pages by 150 ms. It uses the conventional commit form with the fix(web) scope. The title is specific and accurate.

Full details: Description check

Explanation

The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section explains the frame drops and the reproduction steps. The Change section explains the 150 ms wait for newly mounted pages. The Scope section says this is a bug fix and links the related PR #41537 as the prior work, but it says there is no issue for the bug and gives a reason. The Verification section names a focused browser test, gives measurements with the build and environment, and lists what was not checked. The description does not include screenshots, but the template asks for them only for UI changes, and this change is a performance fix with no visible UI change. The description also has no line stating which agent or model did the work beyond a short note, which the template requests, and it includes a model name that the template's sentence asks for, so this is covered.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a369642 and ba883c0.

Files selected for processing: 2

  • apps/web/src/components/files/PdfViewer.browser.test.tsx
  • apps/web/src/components/files/PdfViewer.tsx

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

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 23, 2026
@juliusmarminge juliusmarminge added takeover:needs-julius Takeover done; route gate says Julius decides and removed takeover:in-progress A takeover lead is working on this PR labels Nov 23, 2026

This branch has not been deployed

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

Labels

size:S 10-29 changed lines (additions + deletions). takeover:needs-julius Takeover done; route gate says Julius decides vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants