Skip to content

Spread is not consistent with attribute for style #15309

@adiguba

Description

@adiguba

Describe the bug

I just found that spreading the style attribute have a different result from setting it directly

These two lines are not equivalent on client-side (server-side is OK) :

<div {style}></div>
<div {...{style}}></div>

=> That's because the attribute style is set via element.setAttribute(), but with spreads it set via style.cssText

} else if (key === 'style' && value != null) {
element.style.cssText = value + '';
} else if (key === 'autofocus') {

I think that this line could fix the problem :

		} else if (key === 'style' && value != null) {
-			element.style.cssText = value + '';
+			set_attribute(element, key, value);
		} else if (key === 'autofocus') {

Reproduction

https://svelte.dev/playground/hello-world?version=5.20.1#H4sIAAAAAAAACm2RUU_CMBDHv0pTH4AEhiY-dXOJURJNRB9EXxgPXXcjC127tDeEkH1322YEEXIv7e_-979e70AVr4Ey-gJSavKjjSzIEIoKoRjRMS0rCZay5YHivvE6Dxzvqx6bJrJbkOhZzi1c40IrBIXOhiZWmKrBNFMZSkBicS-BPJBBzc26Uuy-2cU5F5u10a0q2E155yMWQrDbWGipDVsbANWfc9nCIM5UMj35qufXb8IcK6otOYQGXZpM3S09wiiK-sQpk6mnr8_Fx3wye5vNZ--LYCFai7qegITaDfDH7TyRXpGe97jQ-0hCPvzF_2rPMiwq20i-ZySXWmxiD7tL9TLYrBjjJYIZe4Eb6ZweHftVMMIRzTBIRkdf94nhPW5jCDukDE0L3ar7BYgUaukjAgAA

Logs

System Info

REPL

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting submitterneeds a reproduction, or clarification

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions