Skip to content

CSS Custom Properties as props needs to be explicitly passed #15943

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

Open
JReinhold opened this issue May 17, 2025 · 1 comment
Open

CSS Custom Properties as props needs to be explicitly passed #15943

JReinhold opened this issue May 17, 2025 · 1 comment

Comments

@JReinhold
Copy link

JReinhold commented May 17, 2025

Describe the bug

When passing CSS Custom Properties as props to components, they need to be explicitly set as props and can't be part of spreaded objects or other syntaxes that wouldn't explicitly name the props.

Presumably this is because Svelte does static analysis to determine if a prop is a CSS custom property (... because its name starts with --?), and so if you don't set it explicitly, it will fool the static analysis engine, even though at runtime it is the same code.

I'm struggling with words, but I think the reproduction explains what I mean:
https://svelte.dev/playground/01ffe5b59fe8481ab06c14fa0feea420?version=5.30.2

If my assumption is correct and the problem is static analysis, then I think it's fair that it is this way, then I just think this gotcha needs to be explicitly documented in https://svelte.dev/docs/svelte/custom-properties

Originally discussed in this Discord: https://discord.com/channels/457912077277855764/1373334368243679394/1373334368243679394

Reproduction

https://svelte.dev/playground/01ffe5b59fe8481ab06c14fa0feea420?version=5.30.2

Logs

System Info

Svelte playground with version 5.30.2

Severity

annoyance

@paoloricciuti
Copy link
Member

Yeah the problema Is static analysis...to work we need to wrap the component in an element with display contents and the css variables as inline styles.

But yeah let's keep this open to document this behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants