-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Scoped styles for <svelte:element> #7443
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
Comments
Could you provide us REPL? |
The issue is, that can't use the generic tag selectors like this: Your workaround with using classes works for me right now tho :D |
Ah I got it. Thank you! I think this workaround also useful. |
I guess when we try to see if the selectors match any element, we can make <div>
<svelte:element class="a" this={...}>
<span />
</svelte:element>
</div>
<style>
/* used selectors */
h1 { }
p span { }
ul.a { }
div > b > span { }
div > i { }
/* unused selectors */
h2 div { }
h3.b { }
</style> |
oops, we are posting at the exact same time lol. Can I try? |
A thought, How about introducing a way for users to tell the compiler to not purge certain selectors? Essentially what people do with There's already an issue proposing something similar, will link it and carry over the discussion there. |
I love this idea, maybe making a special keyword like :global() something like :keep() or whatever will fix all the issues of purging what the compiler sees unused css |
Could you please tell me where is that? And personally, it sounds like it is transferring the responsibilities of the Svelte compiler to userland regarding purging CSS. |
I'd also love to opt out of purging (while keeping scoping). |
Found it #5804
It is kinda, (technically it'd be the responsibility of not purging CSS), IMO it's fine in this case, we can't expect Svelte to bend for every possible scenario that people can conjure. Forgive me if I misunderstood the current proposed solution to this issue, my interpretation was that if the component has a dynamic class name somewhere then Svelte will ignore unused CSS in that component? Which I think opens up more possibilities for pitfalls, and an explicit opt in to keep styles would be a lot better here. |
@baseballyama yup go for it 🚀 |
There is actual problem here regarding CSS purging, so I think we need to discuss about it. |
@tanhauhau what about the suggestion of making something like |
the repl didnt use |
Different issue i guess, but it just popped up with this discussion, the idea of preventing svelte from purging certian classes (conditional classes), same as using |
This is supported now in 3.51.0 - https://svelte.dev/repl/23d982fc6f4f4f06a6aa227860fa2d84?version=3.51.0 |
Describe the problem
Currenlty scoped styling for any dynamic tags generated with svelte:element give the generic warning "Unused CSS selector", not really sure if that's a bug or it should be added as a feature!
Describe the proposed solution
add support for scoped styles with svelte:element
Alternatives considered
currently the only solution to fix that problem is using global styles
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: