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: In CSS, mixing :global() and various selectors throws an error #9398

Closed
pimdewit opened this issue Nov 12, 2023 · 5 comments · Fixed by #10055
Closed

Svelte 5: In CSS, mixing :global() and various selectors throws an error #9398

pimdewit opened this issue Nov 12, 2023 · 5 comments · Fixed by #10055
Milestone

Comments

@pimdewit
Copy link

Describe the bug

Some CSS selectors throw an error when mixed with :global().
This seems to only happen svelte 5, not the earlier versions.
From my experimentation I am relatively sure it happens when adding selectors with ( and ), e.g :where(), :has(), :is(), etc

Reproduction

:global(:where(selector))

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAEyWNywqDMBBFfyXMSiEi3aZS6HdUF1FHGzp5kIwWEf-9Cd1c7gPOPWExhAnU6wSnLYKCZwgggY9QQtqRGHNOfotTabrZ7I-uLdq73nWJD8JiWa3kR02V-r4xYhWk8CTFRnUtzrL3bHVcjWtG8tOnSawjK3FDey_rlVntH5bvrJ_NYnAGxXHDa7h-2NTG_6kAAAA=

:global(:not([attribute]))

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAEyVNywqDMBD8FdmTQlPpNZVCv0M9RLPq0rxIVqmI_15DL8O8mDlgIoMJZHuAUxZBwjsEuAHvIYu0oWG8dPJrHLPTaNpeTZ2xc51rEu8GM-V7pHERjF8u5Gz8oEwpneeyVZGUWEhrdH1VFUcud2xVnMmJwfjxIxKryLJ4oH3m9LyG6__y9W29polQg-S44tmfPzzfVnS2AAAA

:global(:is(.class)

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAEyWOwQrCMBBEfyXsqYLoPVZB_IR6Mx7aZmsXtknJbgul9N9t9DiPecOs0BGjgH2tEOoBwcJ9HOEIuow5yIysuGeJU2ozKT3NpuVa5OpAUdTBzQWnz57EPKrKSB8n9qZBQ2GumbwL5XmXciuUogvjT7Afjk3NhSUpTnnoYNbMnbaRY7Imob9ksOWBv7cfGaKnjtCD1TTh9t6-jKj2HMMAAAA=
^ This demo should be invalid, but does not throw an error

Logs

No response

System Info

System:
    OS: macOS 14.2
    CPU: (8) arm64 Apple M2
    Memory: 59.17 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  Browsers:
    Chrome: 119.0.6045.123
    Chrome Canary: 121.0.6123.0
    Edge: 118.0.2088.69
    Firefox Nightly: 120.0a1
    Safari: 17.2
    Safari Technology Preview: 17.4
  npmPackages:
    svelte: ^5.0.0-next.1 => 5.0.0-next.1

Severity

annoyance

@jasperkelder
Copy link

jasperkelder commented Nov 12, 2023

I just experienced the same problem, for now this workaround seems to be useable:

<a href="#">Test</a>

<style>
	/* Used to work but now doesn't */
	/* :global(a):hover {
		color: green;
	} */

	/* Still works */
	:global(a:hover) {
		color: green;
	}
</style>

Edit: There also seems to be something funky going on in the Svelte 5 repl. When :global() is used the style remains applied even after removing it from the code. This doesn't happen in the Svelte 4 repl.

@benmccann benmccann modified the milestones: 5.x, 5.0 Nov 12, 2023
@NickStemerdink
Copy link

NickStemerdink commented Nov 24, 2023

Same for a selector like this:

:global(> *:nth-child(1)) {
}

Error:
CompileError: Error while preprocessing **/src/lib/layout/Main.svelte - Expected a valid CSS identifier

@NickClark
Copy link

NickClark commented Dec 12, 2023

Same error: Internal server error: /Users/.../+page.svelte:107:10 Expected a valid CSS identifier

image

@johannesmutter
Copy link

CSS nth-child selector larger than 9 don't work e.g. :nth-child(10n) will throw this error:
CompileError: Expected a valid CSS identifier

Svelte 5 REPL to reproduce

nth-child

@brunnerh
Copy link
Member

@johannesmutter There already is a separate issue for that here:

dummdidumm added a commit that referenced this issue Jan 2, 2024
closes #9398 (the other things in that issue are already addressed)
dummdidumm added a commit that referenced this issue Jan 2, 2024
closes #9398 (the other things in that issue are already addressed)
closes #10019
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.

7 participants