Skip to content
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 get uncorrectly removed / how to pass down styles? #4281

Closed
manuschillerdev opened this issue Jan 17, 2020 · 1 comment
Closed

Styles get uncorrectly removed / how to pass down styles? #4281

manuschillerdev opened this issue Jan 17, 2020 · 1 comment

Comments

@manuschillerdev
Copy link

Describe the bug
In https://svelte.dev/docs#script there is a part on how to expose reserved keywords like class to parent components.

I tried to include this in my app, but the optimizations / scoping of styles prevent that with the current version 3.17.1

To Reproduce
https://svelte.dev/repl/59207aa8c9284598a44489414267796c?version=3.17.1

Actual behaviour

  1. If the Child component is the only element in the markup that uses the class, the styles are marked as unused. I suppose therefore they will just become removed during compilation, right?
  2. If a second element using the styles is placed in the markup, svelte correctly generates the svelte- hash class for the current scope, and also correctly applies the styles to the second element. The first element however does not get the scoped svelte class applied.

scoped styles do not work when passing down the classname

Expected behavior
If I pass down the classname to a child component, I expect the styles to not being marked as unused and svelte to apply the scoped hash class to the child component.

@Conduitry
Copy link
Member

This feature is working as intended, and this issue is basically a duplicate of #2870/#2888, which is not how we want to handle styling child components.

A prop called class on a component shouldn't be treated specially. You can manually declare a prop called class and use it however you want within the component, and/or you can use :global() around parts of selectors to refer to elements in other components (including child components).

You may also be interested in sveltejs/rfcs#13 which is a proposal for how to style child components using an API explicitly defined by the child.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants