Menu

Why rapid zoom breaks a PDF.js canvas render
📰

Why rapid zoom breaks a PDF.js canvas render

DEV Community: frontend·KomoPDF·4 days ago
#UKZBkhxK
#devtofrontend#devto#dev#canvas#request
Long article (878 words) — no AI summary yet.
Reading 0:00
15s threshold

A user clicks zoom twice, and the PDF page disappears. The console reports that the same canvas is already in use by another render operation. A viewer can hit this when a new zoom, rotation, or page selection starts drawing before the previous PDF.js render has finished.

The tricky part is that cancel() starts cancellation; it does not make every asynchronous step in your viewer disappear. You still need to wait for the render task's promise to settle before reusing that canvas. You also need to ignore older page requests that finish loading after a newer request has arrived.

A race with two different clocks

Suppose the user selects page 3, then immediately selects page 4. Both getPage() calls run asynchronously. Page 4 can become available first, while the older page 3 request is still pending.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.