-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[styles] Replace classnames with clsx #14152
Conversation
Benchmark https://github.com/lukeed/clsx/tree/master/bench, although this is in isolation, so the proportional benefit to component mount time may be negligible... |
The main benefit for me is esm support which allows me to skip cjs-to-esm conversion for my rollup build. |
Original package is umd which is useless for bundling. |
This is something I have been wondering about. What do you guys think of this change? -import classNames from 'classnames';
+import cx from 'classnames'; |
I will prefer clsx now. We may even mention about it in docs. People will use whatever appears in this project. I will migrate pickers too. |
The release of lukeed/clsx@08d028f is a blocker. |
Please open a separate issue/PR for the As for the Is a micro benchmark really the argument here? Does anybody have stats on portion of execution time a Note about bundle size: Again this only apply in isolation. How many packages are already pulling in We should have answers to this before throwing out a battle tested package with 2.4M downloads/week over a 18 days old package that has 150 downloads/week. Even if the author is well known we should not make these decisions lightly. |
I have opended JedWatson/classnames#187. |
It was already asked. They afraid legacy. Treeshaking will work with clsx. ClassNames is not treeshakable because of umd wrapper. So makes sense. @oliviertassinari People will use what we recommend. Changing package in favour of more maintainable is not a problem. I will propose tiny-warning soon because its maintainer didn't stuck on mirorring facebook once in a year without a chance for improvement from the community. |
What do you shake from a one function package is what I'm asking. |
@eps1lon If classnames is a transitive dependency and material-ui being imported from index.js (assume it's fully treeshakable) but imported component does not use classnames then it still will be appeared in the bundle. clsx will not. |
Hey there, Thanks for the consideration, very cool! I'm not trying to advocate That said, I just want to address a few points:
Anyways, that's it for now~! Will check back in a few days/weeks, but I'm happy no matter the outcome. Thanks again! |
I could've sworn that this is not the case so I tried this with webpack@4.22.0 and |
Rollup will include it |
Could you provide some context why rollup does not solve this issue when webpack is capable of solving this without additional configuration? Sounds like a fix to rollup would be more appropriate |
I'd say the problem is |
I was very skeptical about this statement. If rollup would only analyze code then it shouldn't have a reason to include
This indicates that the problem is with the inability to shake components from the bundle. I don't see why a switch from I also added a bundle that used the build from this branch and it will still include @TrySound Could you provide an example that illustrates bundles with |
@eps1lon I said "assume material-ui is treeshakable". clsx will be treeshaked if it's used by a package based on hooks for example. |
Switching to Why so much talking about switching to obviously better package? Why stuck with legacy because "everybody use it"? |
Before moving forward, I think that we should consider the alternatives. Here is one classcat. Looking at their benchmark, clsx seems to be slower than classNames. Maybe we can find a better one? |
@oliviertassinari Probably because it does not access So stay with clsx? |
I don't think it's very hard to write a codemod that transforms every variadic call of |
material-ui-pickers has already migrated to clsx. |
This comment has been minimized.
This comment has been minimized.
33f5368
to
abe495c
Compare
So it isn't just me that believes this then! |
I'll decrease my bundle because we use clsx and use at least on library that uses clsx. This will be the last use of classnames for us. Regardless, material-ui should choose the best library for the job. It is one of the most popular UI libraries in the world and our choices here signal good choices for others because they know we research and debate the small things. LGTM. |
In that spirit then 😇:
Respectfully, that's perhaps the worst case of anecdata I've seen in a long while. https://www.npmjs.com/browse/depended classnames: 19/~450,000 The odds of overlap are far from insignificant. However, as I said in chat, I'm willing to suck it up for the sake of a few hundred bytes. But lets not pretend the overhead isn't real (even if tiny) for a likely majority users. |
abe495c
to
c57e2b0
Compare
c57e2b0
to
3b6a2a4
Compare
The best way to gather more data points around this change is to actually release it. We gain more user feedback with the alpha releases of v4. Also, I still hope we can completely get rid of this package in v4… |
Just tried to update to 4.0.0-alpha.0 to play with it but getting
Is there something I missed in the migration docs? Should I create a separate issue to track? |
So I looked at the diffs and just made the changes inline and it worked. -import classNames from 'classnames'; and replaced classNames with clsx and my project loaded. I'm guessing the next patch with fix this. Thanks |
@juniorclarke Thanks for reporting this. Fix is proposed: #14506 |
hello i'm beginner in react so can someone explain to me What is className and function of className |
@eimanhakimy without going into details:
|
For reference: https://github.com/lukeed/clsx#readme |
clsx new faster replacement for
classnames with esm support.