question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PDFPageProxy.prototype.render().promise resolves even after being canceled.

See original GitHub issue

Attach (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:

  1. call PDFPageProxy.prototype.render()
  2. 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:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Snuffleupaguscommented, Sep 30, 2020

That’s exactly my use-case. My abstraction over the viewport scaling (i.e. zoom) called the render method and called cancel at the wrong time.

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. the simpleviewer example there or perhaps also the mobile-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.

1reaction
Snuffleupaguscommented, Sep 30, 2020

renderTask.promise should not resolve.

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):

If you are developing a custom solution, first check the examples at https://github.com/mozilla/pdf.js#learning and search existing issues. If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us in the Matrix room – keep in mind that just code snippets won’t help us troubleshoot the problem.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found