-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Try: Replace classnames with clsx (outdated) #61091
Conversation
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
1 similar comment
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Lots of CI failures that seems completely unrelated to the changes (basically a grep replace of classnames -> clsx. Anyone know why this is happening? Is this just a side effect of touching a lot of repo-wide code? |
I'd suggest double-checking if it's really unrelated. There seems to be some relation at first glance: |
@tyxla most do seem unrelated but I also stumbled upon that one. I'm puzzled about that instance because I can't find what's being referenced there. Literally grepping for "classnames" case insensitive doesn't find any more relevant references in code. I feel like I'm missing something 🤔 |
Have you tried rebasing to the latest |
@tyxla that was it. Pushing fix. Thanks! |
Ok got some tests related to |
This is ready for review now. |
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 think we should include the restricted import eslint rule in this PR so nobody wastes their time figuring out what happened.
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.
This looks good and works well. 👍
I'd add some entries to all existing CHANGELOGs of affected packages since it's a change worth mentioning.
Since it's a change that affects the entire repo, perhaps we could wait for a couple of days before merging, in case someone has blocking feedback.
Thanks @DaniGuardiola 🙌
Is there any reason why the bundle size comment is not visible on this PR, I wanted to check the impact. I believe this needs to be announced in #core-editor at least to bring some visibility among contributors but other than that, it seems fine to land to me. |
I'm curious too. Could someone more knowledgeable look into it? :)
Good point 👍 will make sure to do this after merge. |
It seems it's because you're using a fork. I saw that you already have 3 PRs merged into the repo so I added you to the Gutenberg team to be able to create branches and merge approved PRs. If you want to check the bundle size impact before merging here, you'll have to recreate another PR using a branch in the main repo I guess. |
Closing this in favor of #61138 since I've continued work there. |
Important: superseded by #61138
What?
This PR attempts to replace classnames with clsx across Gutenberg, which is a faster and lighter alternative.
@tyxla already did this in calypso: Automattic/wp-calypso#89843
How?
It's a drop-in replacement. All
classnames/dedupe
instances were also safe to replace, except for one case where an obscure feature was being used - that was trivially replaced with equivalent code (seeremoveAspectRatioClasses
commit for details).Size gains
With
classnames
andclassnames/dedupe
we added 1.14kb (minified + gzipped) to the bundle. See:https://bundlejs.com/?q=classnames%402.5.1%2Cclassnames%402.5.1%2Cclassnames%402.5.1%2Fdedupe%2Cclassnames%402.5.1%2Fdedupe&treeshake=%5B*%5D%2C%5B%7B+default+%7D%5D%2C%5B*%5D%2C%5B%7B+default+as+d2+%7D%5DWith clsx, we only add 241B (minified and gzipped). See: https://bundlejs.com/?q=clsx%402.1.1&treeshake=%5B*%5D
That's about a kylobyte of savings.