Only add static media once per bundle in the diff viewer.
Review Request #14545 — Created Aug. 1, 2025 and submitted
We're able to display certain binary files in our diff viewer. A binary file is associated with a review UI, which renders the file. Some Review UIs have static media bundles which get loaded onto the webpage. Previously, we'd load these bundles unconditionally. However, now that we use review UIs in the diff viewer, we've discovered that the static media of a review UI gets loaded multiple times onto the page, depending on how many instances of the review UI are in the diff viewer. This lead to a problem with Power Pack's PDF and Office Document review UIs in the diff viewer. The review UIs include a bundle for the pdf.js module, which handles PDF rendering. This module sets up some global state that is meant to facilitate rendering multiple PDF documents on one page. However, since we were reloading the review UI's static bundles everytime a new instance was added to the page, this global state would get overwritten each time which would lead to PDF rendering issues. This change updates the diff viewer page to keep note of what static bundles have already been loaded onto the page, and to skip loading any existing bundles when rendering a new diff reviewable onto the diff viewer. This ensures that any state from the static media of a review UI will be shared between all instances of that review UI type on the page. And we're avoiding unnecessary requests for loading the duplicate static media.
- Ran unit tests (no new failures).
- Ran JS unit tests (no new failures).
- Tested with multiple PDF and Office documents in the diff viewer,
as well as non-binary files. - Tested changing the first and last commits in the diff viewer.
- Tested with only non-binary files in the diff viewer.
- Tested viewing standalone review UI pages.
Summary | ID |
---|---|
1a5cbe3f69f3cdc641d5c16949b7ab36d21fb7ac |
Description | From | Last Updated |
---|---|---|
Elsewhere, we name this css_bundles and the JavaScript js_bundles. Maybe css_bundle_names and js_bundle_names would be appropriate here. That'll help differentiate … |
|
|
The diff viewer code doesn't have anything else about attachments or review UIs. This is probably better done in reviewboard/reviews/views/diffviewer.py:ReviewsDiffViewerView.get_context_data, … |
|
|
I assume there's a circular import if we put this at the module level? |
|
|
line too long (82 > 79 characters) Column: 80 Error code: E501 |
![]() |
|
You could combine the statements for these. |
|
|
Same comments here. |
|
|
This should be safe to import at the file level now. |
|
|
And probably these to match. |
|
|
No need for the backticks here (or really the one below, but it was already like that). |
|
|
New unit tests can use () => instead of function(). We used to use function() because older Jasmine required that, … |
|
|
We should be documenting these. The others didn't get documented, but at least for new ones it'd be worth doing … |
|
|
Can you swap these so they're in alphabetical order? |
|
|
line too long (82 > 79 characters) Column: 80 Error code: E501 |
![]() |
|
This should go below the next option (alphabetical). |
|
|
This line's too long. |
|
|
Can you add a blank line between these, so it doesn't get lost with the commented one? |
|
-
-
The diff viewer code doesn't have anything else about attachments or review UIs. This is probably better done in reviewboard/reviews/views/diffviewer.py:
ReviewsDiffViewerView.get_context_data
, where we iterate overcontext['files']
and add a bunch of additional stuff.css_media
andjs_media
would then become fields ofSerializedReviewsDiffFile
(defined in that same file)
-
Looks great. I just have comments on naming and some small modernization nits.
-
Elsewhere, we name this
css_bundles
and the JavaScriptjs_bundles
. Maybecss_bundle_names
andjs_bundle_names
would be appropriate here. That'll help differentiate from, say, arbitrary CSS or JavaScript URLs. -
-
-
-
-
-
New unit tests can use
() =>
instead offunction()
.We used to use
function()
because older Jasmine required that, but now() =>
is recommended.Same with other tests.
-
We should be documenting these. The others didn't get documented, but at least for new ones it'd be worth doing so intent is clear.
-

- Commits:
-
Summary ID 58f0c143b4dd3d9fc23f5a42685b401366c35f28 e3cd17ac5c048c48a6fd3d0797271d5da9481492 - Diff:
-
Revision 2 (+1088 -56)
Checks run (2 succeeded)

- Change Summary:
-
Added an optimization where we try take advantage of already loaded file attachments instead of hitting the database, when possible.
- Commits:
-
Summary ID e3cd17ac5c048c48a6fd3d0797271d5da9481492 1a5cbe3f69f3cdc641d5c16949b7ab36d21fb7ac - Diff:
-
Revision 3 (+1118 -62)