Repository navigation
perf(web): defer PDF repaints during Fit width drags with usePdfResize - #294
Closed
orbitingflea wants to merge 1 commit into
Closed
orbitingflea wants to merge 1 commit into
orbitingflea wants to merge 1 commit into
Conversation
|
This PR changes the test suite by +11 test cases (browser +11, unit 0, server 0). New browser test files: Keep tests that would fail for a real reason, and test logic below the UI where it can be. See Testing. |
orbitingflea
force-pushed
the
feat/pdf-resize-perf-v3
branch
from
November 24, 2026 20:58
14ad4b8 to
353e0ff
Compare
Thread transfer impact
This comment will update automatically after the next completed run. |
A fork hook, usePdfResize, holds the width that pages were painted at while a panel resize drag (the body cursor useResizeDrag sets) changes the viewer's width in Fit width, so PdfPage does no pdf.js work and the browser stretches the bitmap. Pages that enter the off-screen preload range during the drag wait; pages on screen mount and paint. 150 ms after the last width change, or at once on a zoom change, a new document or a width change outside a drag, the hook passes everything through and each mounted page repaints once at the final width. Window resizes and other one-off width changes keep upstream behaviour. Upstream's resize anchor keeps the reader's place; PdfPage and the layout helpers are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
orbitingflea
force-pushed
the
feat/pdf-resize-perf-v3
branch
from
November 24, 2026 23:11
353e0ff to
cfa7247
Compare
Owner
Author
|
Closing: upstream pingdotgg#41537 already fixes the PDF resize page jump and delivers most of the drag speedup with zero fork surface. Keeping this area aligned with upstream. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Behaviour change
Behaviour change: yes, Fit width panel resize drags stretch painted pages. Pages repaint sharp after.
Why
Keep the right-panel PDF viewer smooth during Fit width drags, which cancel unpainted preload renders.
What changed
PdfViewer.tsxusesusePdfResize. In a panel drag,paintWidthholds so bitmaps stretch, mounted pages stay in preload, and new off-screen pages wait. Holds end 150 ms after the last drag width change, or at once on a zoom change, new PDF, or non-drag width change.Scope
PdfPage, layout, scroll, links, and Find are unchanged. Only panel drags hold. Window resizes, maximize, fixed zoom, and height-only resizes keep upstream behaviour.Tradeoffs
Sharp pages appear 150 ms later. Mid-drag text and Find keep painted scale.
Blast Radius
Only Fit width panel drags in the PDF viewer change.
Verification
Eleven Chromium tests, existing PDF and file tests, format, lint, typecheck, knip, and React Compiler pass.
Implementation, tradeoff, and test details
PdfPagekeys repaints on page width, which changes each frame of a Fit width drag. Painted pages wait 150 ms. Unpainted pages start a pdf.js render, text-layer rebuild, and annotation fetch at once. The next frame cancels that work and drops caches. Narrower pages are shorter, so more enter preload and loop. Upstreampingdotgg/t3code#41537keeps scroll, but still runs these renders.apps/web/src/fork/pdfResize/usePdfResize.tsholds{ pdf, paintWidth, mounted } | null.apps/web/src/components/files/PdfViewer.tsxreadsvisiblefromusePdfResizeand passespaintWidthtoPdfPage. A hold starts only on a Fit width change with a loaded PDF whileuseResizeDragsetsdocument.body.style.cursortocol-resize. It ends 150 ms after the last drag width change, or at once on a zoom change, new PDF, or non-drag width change. Window resizes, maximize, panel toggles, and post-release width changes pass through. Mounted pages stay in preload. Pages that leave unmount and remount if scrolled on screen. Scroll,#41537,saveView, andrestoreVieware unchanged.PdfPage's 150 ms wait. At settle, mounted pages rebuild text layers and drop pdf.js caches once, like upstream. Mid-drag text and Find clip until settle. A 150 to 300 ms pause may settle and repaint on resume. Scroll memory matches upstream.apps/web/src/fork/pdfResize/PdfResize.browser.test.tsxtests eleven real-resize cases on a 12-page PDF in Chromium. A panel drag holds the reader's page with zero paints, then repaints sharp. Pages leaving and re-entering preload do not paint. Growth from a page top keeps the page number. Mid-drag scrolls hold position. Pages scrolled on screen or crossing the edge paint once in range. A slow drag of 100 ms steps stays held 140 ms after the last step and expands at 160 ms. A non-drag width change mounts pages at once, and a post-release width change before settle ends the hold. Both repaint on-screen pages within 160 ms. Zoom and height-only resizes pass through. Tests fail if you drop the paint-width hold, preload filter, height-only guard, or cursor check, keep the hold on a non-drag width change, or time settle from the first width change.