Skip to content

Cancel superseded PDF renders so a stale zoom can't paint the page - #44

Merged
mark-kraemer merged 2 commits into
mainfrom
fix-orphaned-pdf-render-task
Oct 7, 2026
Merged

mark-kraemer merged 2 commits into
mainfrom
fix-orphaned-pdf-render-task

Conversation

@mark-kraemer

@mark-kraemer mark-kraemer commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Why

On slower machines the PDF viewer could open a page drawn at the wrong zoom or garbled, while the toolbar showed the right percentage, until the user zoomed out and back in. A cancelled render was clearing the handle that already belonged to the newer render. The next zoom change then couldn't cancel that render, and the stale one painted over the canvas. Now each render only clears its own handle, so every superseded render is cancelled.

A page load changes zoom two or three times in quick succession (default, fit-to-width, refit on resize), which is why this shows up on page open and not just on manual zooming.

What Changed

  • Cancel every superseded page render so only the latest one draws
  • Remove a stray ) rendered below the pages
  • Bump version to 0.0.11

Screenshots

Demo page with a heavy vector PDF, three back-to-back zoom changes, 6× CPU throttle. Both show 110% in the toolbar. Before, pdf.js also logs "Cannot use the same canvas during multiple render() operations".

Before After
Before: the stale render paints the page upside-down and garbled After: the page renders correctly at 110%

🤖 Generated with Claude Code

A page re-renders each time its scale changes. When a render was
cancelled, its catch block cleared _renderTask even though that field
already pointed at the newer render. The next scale change then
couldn't cancel it: it resized the canvas under the still-running
render, and pdf.js rejected the new render because the canvas was in
use. The stale render finished drawing at the old zoom.

Only clear _renderTask when it still holds this call's own task.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mark-kraemer mark-kraemer self-assigned this Oct 7, 2026
The pages loop in the canvas template closed with `)})`, leaving a
literal ")" in the container under the last page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mark-kraemer
mark-kraemer merged commit 84da219 into main Oct 7, 2026
1 check passed
@mark-kraemer
mark-kraemer deleted the fix-orphaned-pdf-render-task branch October 7, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants