Skip to content

Svelte 5: Non-top-level :has() selector is considered unusedย #13717

@hyunbinseo

Description

@hyunbinseo

Describe the bug

The <legend> element appears as

<form action="">
  <fieldset>
    <legend></legend>
  </fieldset>
</form>

<style lang="postcss">
  fieldset:has(> legend) {
    background-color: yellow;
  }
  /* Unused CSS selector "form > fieldset:has(> legend)" */
  form > fieldset:has(> legend) {
    background-color: red;
  }
</style>

I don't think this is an intended change of the following PR, because <legend> clearly appears in the markup.

Reproduction

pnpm i [email protected]                                                       
pnpm check

# ====================================
# Loading svelte-check in workspace:
# Getting Svelte diagnostics...
# 
# /src/routes/+page.svelte:12:2
# Warn: Unused CSS selector "form > fieldset:has(> legend)" (svelte)
#         /* Unused CSS selector "form > fieldset:has(> legend)" */
#         form > fieldset:has(> legend) {
#                 background-color: red;
# 
# 
# ====================================
# svelte-check found 0 errors and 1 warning in 1 file
pnpm i [email protected]
pnpm check

# ====================================
# Loading svelte-check in workspace:
# Getting Svelte diagnostics...
# 
# ====================================
# svelte-check found 0 errors and 0 warnings

Logs

No response

System Info

System:
  OS: macOS 15.0.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 116.39 MB / 16.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 22.10.0 - ~/.local/state/fnm_multishells/16744_1729417203997/bin/node
  npm: 10.9.0 - ~/.local/state/fnm_multishells/16744_1729417203997/bin/npm
  pnpm: 9.12.2 - ~/.local/state/fnm_multishells/16744_1729417203997/bin/pnpm
Browsers:
  Chrome: 129.0.6668.101
  Edge: 130.0.2849.46
  Safari: 18.0.1
npmPackages:
  svelte: 5.0.0-next.266 => 5.0.0-next.266

Severity

blocking an upgrade

Metadata

Metadata

Assignees

Labels

bugcssStuff related to Svelte's built-in CSS handling

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions