-
-
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
Not removed "unused" class from CSS if it used by component #10618
Comments
in fact, since [email protected], tailwindcss dark mode(based on class strategy) will also not work, because the for example: <h3 class="text-black dark:text-white">title</h3> the :is(.dark .dark\:text-white) {
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
} but,,,, current component does not know what |
A |
And one more reason not to do this:
The proposed change I suggested will violate this idea. This issue has been discussed five years ago, but Svelte requires a different approach. I've always made components as independent as possible, but things like hiding/showing components at different resolutions were left to the parent. Perhaps in this case, it's better to move this functionality to the Alright, thank you! |
Originally I have already given up replying the rejections on this type of proposal, especially when I see " Come on, I have seen it long time ago, and this is the reason why we are here to make suggestion: please treat Now I'm here because I just watched an interview of Rich Harris and the intro pretty much summarized my feeling on this ticket.
To me, CSS handling in Svelte is always an unfinished feature. We can use it for simple cases. But when we want to go a bit advanced, we have to shift to another way, like using external stylesheet. Personally I use modular Scss. It works very well. But then it is not Svelte anymore. The things suggested by @alkorlos works in intermediate cases, where you already know which properties the end users would like to override. It works if you are the component author and also the end user. But in reality, it doesn't work all the time and CSS class will always be preferred. Svelte is a good framework. But this tiny bit of oversight makes it imperfect. Not saying I will give up using Svelte just because of this, but I wish someday we will see better component CSS class handling in the future. 🙏 |
Describe the problem
In Svelte 5, it's easy to add the
class
prop to a component using runes:Thank you, very convenient!
However, in Svelte 5, component classes are still removed from CSS as unused:
.form__input
will be removed, even when it's actually used. One workaround is to replace.form__input
to:global(.form__input)
, but this isn't convenient and it's generally preferable to avoid using global styles.Expected behavior — not be removed
.form__input
and add to it uniqueHASH
identifier.Describe the proposed solution
Automatically detect usage
class
attribute in component and handle its behavior in a special way.Alternatively, add
$propsClass();
to work with class:Something like @Mooncat25 offered
There may be other approaches available, but this functionality has been very helpful.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: