Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

Image for: Conversation
Copy link
Contributor

jdunck commented Aug 12, 2013

This aids performance in some browsers (where adding/removing a
class which is already present triggers a CSS render anyway).

Copy link
Contributor Author

jdunck commented Aug 12, 2013

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.)

Copy link
Member

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.

Copy link
Member

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).
Copy link
Contributor Author

jdunck commented Aug 12, 2013

I just signed the CLA. I did not find any existing ticket, so created http://bugs.jquery.com/ticket/14250 and referred to 14164.

Copy link
Member

👍

Copy link
Member

mgol commented Aug 12, 2013

@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.

Copy link
Contributor Author

jdunck commented Aug 12, 2013

I just signed the CLA with the commit email as well.

Copy link
Member

Thanks @jdunck!

mgol closed this in c418b94 Aug 19, 2013
mgol pushed a commit that referenced this pull request Aug 19, 2013
Copy link
Member

mgol commented Aug 19, 2013

Landed at c418b94 for master and at 7dfe0ad for 1.x-master.

Copy link

@jdunck - I'd be really interested to know which browser(s) triggered a layout when assigning a className that already existed?

Copy link

@dmethvin - Ah, it causes styles to be recalculated rather an actual layout; good to see this enhancement in!

Copy link
Member

Good point, for that particular case it causes a style recalc, which may be forced if later code queries styles.

mescoda pushed a commit to mescoda/jquery that referenced this pull request Nov 4, 2014
lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
6 participants