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 for "Unused CSS selector" #13779

Closed
jpaquim opened this issue Oct 22, 2024 · 6 comments · Fixed by #13824
Closed

False positive for "Unused CSS selector" #13779

jpaquim opened this issue Oct 22, 2024 · 6 comments · Fixed by #13824
Assignees
Labels
bug css Stuff related to Svelte's built-in CSS handling

Comments

@jpaquim
Copy link

jpaquim commented Oct 22, 2024

Describe the bug

After the upgrade to the stable v5 I'm now getting a few of these false positives, which seem related to the use of the :has() pseudo-class in CSS rules, possibly in conjunction with the shorthand class (.copied in this repro's case).

Reproduction

https://svelte-omnisite.vercel.app/playground/hello-world?version=5.0.5#H4sIAAAAAAAAE41V224jNwz9FWa2i9iox7FRBC1mHRfFtm99KtKnusDKEscmohEVifKlrv-90FxsdxMUfbAxosijw3OomVNRk8VYVH-cCjl6LKo2UEwKp5q8-sn7adyhlRxbq4jvxTU7QSexqIpF1IG8gFVu87QqJK6K5coBaHZRgJP4JPAEX37lgA2Qj6kBw5YDRBJQDcqkzUUtKCmAMuQpanIbQEsygYgGDANSig0bEGw8ByCnyZBJTiDlw9ccEFA6aIRGbZwCZek1qSn8LoCOGlAGGsoPO3Skmgm8JorgOEpIBvCAQZMoIXaQrFWN5g45J1GkfFILSR7wAKhAc9Ow4a6B16RkCj9nSJUEgUIK2PdKDgL6gFt0BgNJDuzYJi9KEHa5U8AYETRZOyiEgAnqtCEl4DIh8CqQkhSm8MtBoxdMWUYnwFor1EpAJ09GSa5gBz4wGXRZxawUOdDJepX7Bq5r0qTAYMSQdxu2mYbKApEBjL2uqZl--ZQttSgg1CC3jn4TM_fRGFSE37J17vnocZGHimuIKM9d6hL-btl_uk6FZk9oMkYWY4dmdHfXA4_btDo53dqg2R9HYzjlIIC2qEIPO-oL7roKAKd2tFHCYaot-TWrYKb7QILPeJBRN4hD7rWLK8_RaAxPSxhd9zLr8QS-n826uvPKLR66cV-u3MotfMDlqUM-L9ZJJDO2Ksaq7zCL8bQquq1VAey0Jf3ydMp9nSG7WVq1Rvu0Kj6zP66K5eKhy14uHjL8yi2iV2556hF_hPvP7dPdPVRw_znDgTDk6vvz4qFNbslFOVpsr6IPOCjYkCv3ZGRbwXyGTS9How5D9PEa5R2G2vK-PFYQdeDewpweNuQqmPVrr4wht6lgfqld86GMW2V4X8GjP7S_-cwf4Dt_gA9a6z5vvyXBMnqlsco8y31QfoDlSHkIKgholdAOBxeGppbQi376ukKtI9skOPjN_ko30GYr1-WaRbi5ri3WN7u9LORISNlLSTAYqnzFhhPWSr9sAidnSp3vbgUfZrPZgCJBuY5aaVJQHcfZdB7f7vvAHoMcqzeQkzZiAvuyJisY3hYLNeQ25XB9KkAVsSTXZ-oUYqbmmdxQ_46c1TZbP_k6PO1H8PRfHf9wo8cN1QrWNoXR3B_G_5c1J7klmAd7ONpQ9FZliSzrlzfj8p7589nHf_n7eFm3RGoOTdU92vxWKx9nHyeQ_we-Q491XfeRmp2Ukf7C28Fvg3vsRmzN1gyXyStN2dXLpek8KHGXP6Q3s3Q1pPMBvm17n1yCKo56K8b93qDL5ZD5zfuqfw0Uk0LwIEUlIeH5z_M_1kgWcgkIAAA=

Logs

No response

System Info

System:
    OS: macOS 15.0.1
    CPU: (8) arm64 Apple M2
    Memory: 109.33 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.17.0 - ~/.local/share/pnpm/node
    npm: 10.8.2 - ~/.local/share/pnpm/npm
    pnpm: 9.12.2 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 129.0.6668.101
    Safari: 18.0.1
  npmPackages:
    svelte: ^5.0.5 => 5.0.5

Severity

annoyance

@Conduitry
Copy link
Member

These feel like two related although potentially distinct issues that we need to make sure are both addressed. One is about class:foo directives, and the other is about pseudoclasses.

@Conduitry Conduitry added the bug label Oct 22, 2024
@brunnerh
Copy link
Member

brunnerh commented Oct 22, 2024

Seems broken for regular element selectors as well (label:has(input) span).

@vnphanquang
Copy link

vnphanquang commented Oct 22, 2024

Found the same issue, I reported in #13717 as well - might be helpful as Simon was working on a fix for a relevant one yesterday.

TLDR current test cases for :has as of 5.0.5 has not covered this particular one yet:

Input:

<x>
  <y></y>
  <w></w>
</x>

<style>
  x:has(y) w {
    color: green;
  }
</style>

Expected:

  x.svelte-xyz:has(y:where(.svelte-xyz)) w:where(.svelte-xyz) {
    color: green;
  }

@dummdidumm dummdidumm added the css Stuff related to Svelte's built-in CSS handling label Oct 22, 2024
@dummdidumm dummdidumm self-assigned this Oct 22, 2024
@enyo
Copy link

enyo commented Oct 23, 2024

Just came here to say that this issue appeared in 5.0.0-next.265.

This is my minimal reproduction: https://svelte.dev/playground/23060df7688c4bb1be84023e56f00996?version=5.0.5

@aryanisml
Copy link

I have raised the PR to fix the issue in internal compiler code. I hope some one will review the PR and will provide approval for go ahead.

dummdidumm added a commit that referenced this issue Oct 23, 2024
I resisted this previously because it felt a bit wasteful, but I now think that there's really no way around this: Instead of only going upwards the tree while matching, for `:has` we go _down_ the tree to see what matches. More specifically, we're collecting the children of the current element and then check if one of those does match the selectors inside `:has`.

This makes the way the code works easier to reason about and also removes some boolean tracking we had to add for the previous approach.

Fixes #13779
trueadm pushed a commit that referenced this issue Oct 23, 2024
I resisted this previously because it felt a bit wasteful, but I now think that there's really no way around this: Instead of only going upwards the tree while matching, for `:has` we go _down_ the tree to see what matches. More specifically, we're collecting the children of the current element and then check if one of those does match the selectors inside `:has`.

This makes the way the code works easier to reason about and also removes some boolean tracking we had to add for the previous approach.

Fixes #13779
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

Successfully merging a pull request may close this issue.

8 participants