-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Only assign className if changed in addClass and removeClass #1331
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
For a bit more context: on Causes.com, we were using addClass on body, often assigning a class that already existed. On mobile, this needlessly triggers re-render and cost about 200ms. (I'm unsure which mobile browser; I'd need to ask a coworker for that detail.) |
Thanks for taking the time to contribute to the jQuery project! Please make sure that your commit message cites a valid bug and that you've signed the CLA. |
I don't see a ticket for this but it seems like a good idea. Please make a new ticket (unless you find one) and mention http://bugs.jquery.com/ticket/14164 which is the umbrella for our layout reduction effort. |
This aids performance in some browsers (where adding/removing a class which is already present triggers a CSS render anyway).
I just signed the CLA. I did not find any existing ticket, so created http://bugs.jquery.com/ticket/14250 and referred to 14164. |
👍 |
@jdunck You need to sign the CLA with the e-mail address you used for commiting; you chose a different one so we need to wait until you re-sign the CLA with the correct mail address. |
I just signed the CLA with the commit email as well. |
Thanks @jdunck! |
@jdunck - I'd be really interested to know which browser(s) triggered a layout when assigning a className that already existed? |
Chrome, for one. https://code.google.com/p/chromium/issues/detail?id=278045 |
@dmethvin - Ah, it causes styles to be recalculated rather an actual layout; good to see this enhancement in! |
Good point, for that particular case it causes a style recalc, which may be forced if later code queries styles. |
…lose jquerygh-1331. (cherry-picked from c418b94)
This aids performance in some browsers (where adding/removing a
class which is already present triggers a CSS render anyway).