Skip to content

Unused CSS selector "*" when only using root pseudo class selector to set CSS variablesΒ #13399

@eighty4

Description

@eighty4

Describe the bug

A component with a <style> block that only uses :root { } to specify CSS variables will log a warning for an unused CSS selector:

2:02:11 AM [vite-plugin-svelte] src/lib/component.svelte:89:1 Unused CSS selector "*"

It seems like every component's CSS has an implicitly added * {} at the bottom of its CSS. All components in my app include the * {}.

Only the component that uses <style> for specifying root vars flags the * {} as unused. Somehow the magic behind the scenes * {} is flagged as used for any components with CSS selectors and properties.

Reproduction

This seems to only trigger metadata.unused if the CSS only contains a root pseudo class selector and the component's markup only contains a Svelte component.

<script>
import MyComponent from './my-component.svelte'
</script>

<MyComponent/>

<style>
    :root {
        --background: #000;
    }
</style>

Logs

No response

System Info

System:
    OS: macOS 14.6.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 145.27 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.9.0 - /usr/local/bin/node
    npm: 10.8.3 - /usr/local/bin/npm
    pnpm: 9.11.0 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 129.0.6668.70
    Safari: 17.6
  npmPackages:
    @sveltejs/vite-plugin-svelte: 4.0.0-next.7 => 4.0.0-next.7
    svelte: 5.0.0-next.259 => 5.0.0-next.259

Fourth message has guaranteed recreation steps.

Severity

annoyance

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