Fix bugs from wrong event targets being used in event handlers.

Review Request #13133 — Created July 3, 2023 and submitted — Latest diff uploaded

Information

Review Board
release-5.0.x

Reviewers

We ran into a bug where sometimes updating a file attachment would create a
brand new one instead of replacing the original one. This happens because we
rely on an HTML attribute to set the file attachment history ID used for
uploading the attachment, which would sometimes be undefined. The
attribute would be undefined when clicking directly on the file upload icon,
which would cause the event target of the click to be the icon element instead
of the <a> element which holds the attachment history ID attribute. To fix
this, we grab the attachment history ID from the model instead. An alternative
solution would be to use $(e.currentTarget) instead of $(e.target) to grab
the event target, which will always refer to the element that the event
handler is attached to instead of the actual element that was clicked.

I audited the rest of the codebase for any similar problems and updated
some areas where we caught the problem but used more expensive solutions.

  • Ran JS unit tests.
  • Tested updating file attachments, uploading new ones, and deleting.
  • Hit the case where updating a file attachment would create a new one, saw
    that the value from $(e.target).data('attachment-history-id') was
    undefined but the value from model.get('attachmentHistoryID') was correct.
  • Tested the expand and collapse buttons for the diffviewer and review
    request page.

Diff Revision 2

This is not the most recent revision of the diff. The latest diff is revision 3. See what's changed.

orig
1
2
3

Commits

First Last Summary ID Author
Fix bugs from wrong event targets being used in event handlers.
880cb43d2d717813458f426f82c7cc10c6eca8d6 Michelle Aubin
reviewboard/static/rb/js/diffviewer/views/diffCommitListView.es6.js
reviewboard/static/rb/js/diffviewer/views/diffReviewableView.es6.js
reviewboard/static/rb/js/views/diffFragmentView.es6.js
reviewboard/static/rb/js/views/fileAttachmentThumbnailView.es6.js
Loading...