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

Svelte 5: Nested styles for snippets - scope issue #10143

Open
johannesmutter opened this issue Jan 10, 2024 · 1 comment · May be fixed by #10208
Open

Svelte 5: Nested styles for snippets - scope issue #10143

johannesmutter opened this issue Jan 10, 2024 · 1 comment · May be fixed by #10208
Milestone

Comments

@johannesmutter
Copy link

Describe the bug

Problem:
If styles are defined as nested parent > child selectors, they do net get applied to the child element inside the snippet.

Workaround:
Use :global() selector or directly target the element.

Expected Behaviour:
The behaviour is consistent to how one previously had to style nested components.
However as the snippet code lives in the same document, the behaviour now seems unintuitive.

{#snippet my_snippet()}
  <span> Hello world </span>
{/snippet}

<div>{@render my_snippet()}</div>

<style>
  div > span, div  span {
    background-color: red;
    /* this doesn't work */
  }

  div > :global(span) {
    letter-spacing: 10px;
    /* this works */
  }

  span {
    text-decoration: underline;
    /* this works */
  }
</style>

Reproduction

REPL to reproduce

Logs

No response

System Info

Svelte v5.0.0-next.32

Severity

annoyance

@pyronaur
Copy link

pyronaur commented Jan 12, 2024

div span {
  /* also doesn't work */
}

Or if I render my_snippet() from within my_snippet, I can't select span span to adjust styles for child elements, I have to do span :global(span)

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

Successfully merging a pull request may close this issue.

3 participants