Skip to content

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

Closed
@manuschillerdev

Description

@manuschillerdev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions