-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Manipulation: Make jQuery.cleanData not skip elements during cleanup #5523
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
Conversation
mgol
left a comment
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 for the PR. Please don't change code formatting, though. Run npm test locally & you'll see the build fails; you need to fix it.
Also, all such changes need tests.
|
@mgol Done |
mgol
left a comment
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.
jQuery.cleanData is not an API you'd call yourself; jQuery calls it. One of the suggested solutions on the issue was to update the internal getAll function to avoid getElementsByTagName which returns a live collection and just falling back to always use querySelectorAll. That also wouldn't require any changes to jQuery.cleanData and it'd reduce size instead of increasing it.
We'd need some perf tests done for this change, though, to make sure we don't regress significantly.
Also, as I mentioned before, all such changes need tests; there are no added in this PR. Make also sure existing tests & static checks are passing; npm test definitely does not pass on your PR.
The majority of the work here is with the perf tests & writing good unit tests, not in actual code changes.
|
@mgol All tests passed done. |
|
Most of my last review still applies. |
|
@mgol Done changed getAll.js and all tests passed |
mgol
left a comment
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.
We still need tests for what this PR is supposed to fix. Also, we need to have some performance tests comparing before & after done with test cases & results posted in a comment on this PR. This is to make sure we don’t regress too much on performance.
|
@mgol I added tests that specifically address the issues I aim to fix and conducted a performance test on the updated Original implementation time: 1 ms |
|
@ac-mmi can you share the test code, please? |
mgol
left a comment
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.
We're getting closer, but I still have some remarks.
Please also share the code for measuring performance so that I can run it by myself.
|
@mgol Code for measuring performance |
Construction of a perf test@ac-mmi the perf tests you provided test just raw performance of various versions of I created a test case using three versions of jQuery:
The first version is the fastest but the third one is faster than the second one. The differences between (2) & (3) in Chrome & Safari are small enough that I'd opt to (2), but in Firefox they are massive. Test case: https://jsperf.app/gifera/1/preview EnvironmentTests done on macOS Sonoma 14.6.1 (23G93) on a MacBook Pro with the M3 Max chip. Browsers:
Results
ConclusionsThe perf difference in Firefox is staggering so I'd go with the |
mgol
left a comment
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 for the updates; see my latest comments. Please make sure to address them all before re-requesting review - I bumped one of the older comments that was not addressed.
mgol
left a comment
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.
Just a few nits, other than that, mostly looks good!
mgol
left a comment
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, this LGTM, but I want to discuss it with the team before merging.
timmywil
left a comment
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.
LGTM
Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
mgol
left a comment
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.
I noticed one more issue.
When doing the change, don't remove the comment we added to src/manipulation/getAll.js via a suggestion comment.
mgol
left a comment
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!
When passing a result of `getElementByTagsName` to `jQuery.cleanData`, convert it to an array first. Otherwise, a live NodeList is passed and if any of the event cleanups remove the element itself, a collection is modified during the iteration, making `jQuery.cleanData` skip cleanup for some elements. Fixes gh-5214 Closes gh-5523 Co-authored-by: Michał Gołębiowski-Owczarek <m.goleb@gmail.com> Co-authored-by: Richard Gibson <richard.gibson@gmail.com> (cherry picked from commit 3cad5c4)

This pull request addresses #5214 issue in jQuery.cleanData where certain elements were being skipped during the cleanup process. The problem occurred when an element removed itself from the DOM during its own cleanup, causing subsequent elements in the list to be missed.