-
Notifications
You must be signed in to change notification settings - Fork 335
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
[JENKINS-69658] - CSP compatibility for summary.jelly #654
Conversation
}) | ||
container.querySelectorAll('a[id$="-showlink"], a[id$="-hidelink"]').forEach(link => { | ||
if (!link.onclick) { | ||
link.onclick = handleShowHideClick; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use addEventListener
like the code removed was using, see https://stackoverflow.com/questions/6348494/addeventlistener-vs-onclick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure - I just made this correction in the latest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Disclaimer: Still haven't run this.) This change request looks wrong since unlike the earlier code, the events are re-initialized on HTTP response without removing previous event listeners? What happens after a few showFailureSummary
, does that collect event listeners?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @daniel-beck
If I understand correctly, this shouldn't be an issue with the new change:
container.querySelectorAll('a[id$="-showlink"], a[id$="-hidelink"]').forEach(link => {
link.addEventListener('click', handleShowHideClick);
link.style.cursor = 'pointer';
since duplicate event listeners cannot be added to elements see docs
https://stackoverflow.com/questions/10364298/what-does-calling-addeventlister-twice-do
Is this what you were referring to?
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point, I had only looked at the previous reference. So this won't cause trouble then. Thanks for the link!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks looks good, (untested)
JENKINS-69658
This PR is an extension of #451 to fix the inline JS in the summary.jelly file.
The failureSummary.js file had to be changed so that it can handle event delegation as some of the elements we are targeting with the fix do not actually appear in the html until the parent is expanded.
Testing done
https://www.loom.com/share/796f46d313e34c8cbbaf85963c1ffb59?sid=20dc0f68-ddca-4f88-a977-1580816dcdab
https://www.loom.com/share/f7a8117e45a54da5a719599f0d1adb08?sid=8c812aef-9c9a-4a81-b662-c49229d68dbf
https://www.loom.com/share/6e3642baf5934fe59e2efdc3f3f0ec3b
Submitter checklist