Re-factor the dispatching of "attachmentsloaded" events, when the PDF document contains no "regular" attachments #12163
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use a
DocumentFragment
when building the attachmentsView inPDFAttachmentViewer.render
This approach is already used in other parts of the code-base, see e.g.
PDFOutlineViewer
, and has the advantage of only invalidating the DOM once rather than for every attachment item.Re-factor the dispatching of "attachmentsloaded" events, when the PDF document contains no "regular" attachments
Since the attachment fetching/parsing is already asynchronous, possibly delaying the dispatching of an "attachmentsloaded" event should thus not be a problem in general.
Note that in some cases, i.e. PDF documents with no "regular" attachments and only FileAttachment annotations, we'll thus no longer dispatch an "attachmentsloaded" event when
attachmentsCount === 0
and instead wait for the FileAttachment parsing to finish. (The use of a timeout still guarantees that an "attachmentsloaded" event is eventually dispatched though.)This patch considerably simplifies the "attachmentsloaded" event handler, in
PDFSidebar
, since the details are now abstracted away from the consumer.Finally, add a check in
_appendAttachment
to ensure (indirectly) that the FileAttachment annotation is actually relevant for the active document.