-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Component scoped styles incorrectly (?) apply to child components of the same type #15913
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
Styles are scoped against other components. To scope styles down to each component instance, it would need to make unique styles for each component instance, which, in most cases, doesn't make sense and will cause performance issues. About the unused selector warning: the compiler just checks whether the selector matches any element in the component's markup: So, I really not sure what else can the compiler do here. The only solution is to write more strict selectors by utilizing |
Yeah, I mean the only I can think of this somewhat working would be to have a counter appended to the style hash, and just increment it per each instance. However, this would mean that:
Which would be, as stated before, detrimental for performance and more complex overall. |
Yea, makes sense. I just didn't expect that, wouldn't have known that from the docs, and didn't understand that intuitively from the way that style scoping seemed to work.
Oh yea, no I get that. I was just pointing out the confusing nature of the compiler dissuading you from doing things like that, due to the scope of styles, but then the scoped styles actually affecting other component instances. |
That's almost exactly what I was thinking when I was trying to think of a solution to this myself. I was thinking it could repurpose the
Ah, damn, I didn't know that. I guess I'm not privy to the way that the Svelte compiler and DOM manipulation works, but that does make sense. Maybe it could be an option on the component somehow, utilizing As is, the behavior is surprising to say the least. |
Describe the bug
This seems to be a regression of #583.
If a component is nested within another component of the same type, the parent component's scoped styles apply to the child component.
Notably:
:global
selector, and decisions made in Don't cascade styles to nested components? #583.Reproduction
You can see this in action here:
https://svelte.dev/playground/4e28edac5a874ee2a82dfd9a874d90d1?version=5.28.6
Logs
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: