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

False positive "Unused CSS selector" on ":global() + .class" #15523

Open
nikolay-makhonin-playhub opened this issue Mar 16, 2025 · 0 comments
Open
Labels
bug css Stuff related to Svelte's built-in CSS handling

Comments

@nikolay-makhonin-playhub

Describe the bug

Svelte incorrectly marks :global() + .class selector as unused and removes it.

Reproduction

REPL: https://svelte.dev/playground/f6023640ca8e4b659c6bbae9966dca97?version=5.23.0

<!-- Toggle.svelte -->
<input type="checkbox" id="checkbox">
<slot />

<!-- App.svelte -->
<script>
  import Toggle from './Toggle.svelte'
</script>

<div>
  <!-- Uncomment this and the selector works -->
  <!-- <span></span> -->
  <Toggle />
  <label for="checkbox" class="btn">Button</label>
</div>

<style>
  .btn {
    background-color: blue;
    color: white;
  }
  
  :global(:checked) + .btn {
    background-color: red;
    color: black;
  }
</style>

The :global(:checked) + .btn selector doesn't work because Svelte removes it as "unused".

Adding an empty <span></span> before the target element makes it work:

<div>
  <span></span>
  <Toggle />
  <label for="checkbox" class="btn">Button</label>
</div>

Logs

System Info

Svelte Repl 5.23.0

Severity

annoyance

@Conduitry Conduitry added bug css Stuff related to Svelte's built-in CSS handling labels Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug css Stuff related to Svelte's built-in CSS handling
Projects
None yet
Development

No branches or pull requests

2 participants