PDFPageProxy.prototype.render().promise resolves even after being canceled.
See original GitHub issueAttach (recommended) or Link to PDF file here: N/A
Configuration:
- Web browser and its version: Brave 1.14.81
- Operating system and its version: Ubuntu 18.04.5
- PDF.js version: 2.6.347
- Is a browser extension: nope
Steps to reproduce the problem:
- call PDFPageProxy.prototype.render()
- call renderTask.cancel() before the task
What is the expected behavior?
renderTask.promise
should not resolve. I’d expect that the promise resolving to indicate that rendering is complete. It instead means that rendering is either complete or canceled.
What went wrong?
renderTask.promise
does resolve after calling renderTask.cancel()
. It’s really nice that there is a cancel method though. Thanks for that and this project generally. It will greatly increase the value proposition of my own products.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
mozilla/pdf.js - Promise from render() resolves prematurely
This seems to be mostly noticeable when the page includes images, but that does not mean the promise will be resolved only before...
Read more >Promise - JavaScript - MDN Web Docs
A promise is said to be settled if it is either fulfilled or rejected, but not pending. Flowchart showing how the Promise state...
Read more >Promise - is it possible to force cancel a promise
I.e., a promise may have been resolved successfully, but by the time you observe it (with await or then ), the cancellation may...
Read more >JSDoc: Source: display/api.js
If PDF data is BASE64-encoded, * use atob() to convert it to a binary ... @return {Promise} A promise that is resolved with...
Read more >Cancelling a Promise with React.useEffect
Quick Example. function BananaComponent() { const [bananas, setBananas] = React.useState([]) React.useEffect(() => { let isSubscribed ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You may perhaps find the
viewer components
examples helpful, see https://github.com/mozilla/pdf.js/tree/master/examples/components, since they provide a higher-level abstraction compared to using the API directly; see e.g. thesimpleviewer
example there or perhaps also themobile-viewer
example.Note that those examples are using the same components that are also used to build the full demo viewer: https://github.com/mozilla/pdf.js#online-demo
Finally, as already mentioned, it’s unfortunately going to be difficult for anyone to provide further assistance without a runnable example here.
Note that as mentioned in the JSDocs, it’s actually rejected when rendering is cancelled; see https://github.com/mozilla/pdf.js/blob/d49b2f6cc2b7ed86da22d55ddb1af0b8a5fe5a1e/src/display/api.js#L2753-L2758 Furthermore, there’s also unit-tests that enforce this behaviour; see https://github.com/mozilla/pdf.js/blob/d49b2f6cc2b7ed86da22d55ddb1af0b8a5fe5a1e/test/unit/api_spec.js#L1766-L1789
Hence it’s quite possible that you’re simply running into the following situation:
If the task is currently rendering it will not be cancelled until graphics pauses with a timeout.
, given that rendering may actually finish before it has a chance to get cancelled.If the above isn’t sufficient to address this issue, please see https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md (emphasis mine):