Clean up detached views when changing revisions/commits in the diff viewer.
Review Request #14565 — Created Aug. 21, 2025 and updated
When we render binary file review UIs in the diff viewer, we receive an
HTML fragment from the server which we inject into the diff viewer. That
HTML includes JavaScript which creates the reviewable view and model objects
for the file.When we change the revision or commits in the diff viewer, the HTML gets
removed from the DOM. However, any Backbone or other JS objects that were
created in that HTML fragment don’t actually get destroyed or cleaned up.
They end up holding unnecessary memory in the browser.To address this, whenever we clear the diff viewer we emit a signal that
FileAttachmentReviewableViews will listen to and remove themselves.
Subclasses can overrideonRemove()
to perform any additional cleanup
needed for their review UI.
- Ran JS unit tests.
- Used in a change where we clean up PDF and Office document review
UIs in the diff viewer. - Tested changing the revision of a diff viewer that contains binary
image files.
-
-
Nice and simple. Glad you caught this.
I wonder if it's worth having a dedicated
cleanup()
method or if we should just letremove()
handle it. Subclasses can already overrideremove()
(and Spina classes now haveonRemove()
more formerly).If there are cases where we wouldn't want to remove the view but have other cleanup, then a dedicated method makes sense.
-

- Change Summary:
-
Use
remove()
directly instead of a newcleanup()
method to do the same thing. - Description:
-
When we render binary file review UIs in the diff viewer, we receive an
HTML fragment from the server which we inject into the diff viewer. That HTML includes JavaScript which creates the reviewable view and model objects for the file. When we change the revision or commits in the diff viewer, the HTML gets
removed from the DOM. However, any Backbone or other JS objects that were created in that HTML fragment don’t actually get destroyed or cleaned up. They end up holding unnecessary memory in the browser. To address this, whenever we clear the diff viewer we emit a signal that
~ FileAttachmentReviewableViews will listen to and clean themselves up. By ~ default the view will remove itself. Subclasses can override the method ~ to perform any additional cleanup needed for their review UI. ~ FileAttachmentReviewableViews will listen to and remove themselves. ~ Subclasses can override onRemove()
to perform any additional cleanup~ needed for their review UI. - Commits:
-
Summary ID ec2d663ad11392f85368856591f8323d067d1306 85b203203020aa1ff6fe712531d8170b8e037d4d