Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent the annotationLayer from, in some cases, becoming duplicated on the first page when the document loads #9001

Merged
merged 1 commit into from
Oct 7, 2017
Merged

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Oct 6, 2017

I don't know if this is a regression, but I noticed earlier today that depending on the initial scale and sidebar state, the annotationLayer of the first rendered page may end up duplicated; please see screen-shot below.

double-annotations

I can reproduce this reliable with e.g. https://arxiv.org/pdf/1112.0542v1.pdf#zoom=page-width&pagemode=bookmarks.
When the document loads, rendering of the first page begins immediately. When the sidebar is then opened, that forces re-rendering which thus aborts rendering of the first page.
Note that calling PDFPageView.draw() will always, provided an AnnotationLayerFactory instance exists, call AnnotationLayerBuilder.render(). Hence the events described above will result in two such calls, where the actual annotation rendering/updating happens asynchronously.

For reasons that I don't (at all) understand, when multiple pdfPage.getAnnotations() promises are handled back-to-back (in AnnotationLayerBuilder.render()), the this.div property seems to not update in time for the subsequent calls.
This thus, at least in Firefox, result in double rendering of all annotations on the first page.

Obviously it'd be good to find out why it breaks, since it really shouldn't, but this patch at least provides a (hopefully) acceptable work-around by ignoring getAnnotations() calls for AnnotationLayerBuilder instances that we're destroying (in PDFPageView.reset()).

Edit: The patch was updated slightly to ensure that we also won't attempt to render an annotationLayer during closing of a PDF document, i.e. after calling PDFViewerApplication.close().

…d on the first page when the document loads

I don't know if this is a regression, but I noticed earlier today that depending on the initial scale *and* sidebar state, the `annotationLayer` of the first rendered page may end up duplicated; please see screen-shot below.

[screen-shot]

I can reproduce this reliable with e.g. https://arxiv.org/pdf/1112.0542v1.pdf#zoom=page-width&pagemode=bookmarks.
When the document loads, rendering of the first page begins immediately. When the sidebar is then opened, that forces re-rendering which thus aborts rendering of the first page.
Note that calling `PDFPageView.draw()` will always, provided an `AnnotationLayerFactory` instance exists, call `AnnotationLayerBuilder.render()`. Hence the events described above will result in *two* such calls, where the actual annotation rendering/updating happens asynchronously.

For reasons that I don't (at all) understand, when multiple `pdfPage.getAnnotations()` promises are handled back-to-back (in `AnnotationLayerBuilder.render()`), the `this.div` property seems to not update in time for the subsequent calls.
This thus, at least in Firefox, result in double rendering of all annotations on the first page.

Obviously it'd be good to find out why it breaks, since it *really* shouldn't, but this patch at least provides a (hopefully) acceptable work-around by ignoring `getAnnotations()` calls for `AnnotationLayerBuilder` instances that we're destroying (in `PDFPageView.reset()`).
@mozilla mozilla deleted a comment from pdfjsbot Oct 7, 2017
@mozilla mozilla deleted a comment from pdfjsbot Oct 7, 2017
@pdfjsbot
Copy link

pdfjsbot commented Oct 7, 2017

From: Bot.io (Linux m4)


Received

Command cmd_preview from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/f523df0de75237a/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Oct 7, 2017

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/f523df0de75237a/output.txt

Total script time: 2.32 mins

Published

@timvandermeij timvandermeij merged commit bbec2ed into mozilla:master Oct 7, 2017
@timvandermeij
Copy link
Contributor

Thank you for fixing this! I think being able to cancel rendering here as well (in addition to the various other viewer components) is a good addition.

@Snuffleupagus Snuffleupagus deleted the AnnotationLayerBuilder-cancel branch October 7, 2017 14:21
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
…lder-cancel

Prevent the `annotationLayer` from, in some cases, becoming duplicated on the first page when the document loads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants