You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Under certain conditions, style: directives get overwritten by the style attribute, instead of being merged.
In Svelte 4 they were always merged.
In Svelte 5 the style attribute is set first, then style: directives are applied onto it (from my observation). However, sometimes the order is incorrect and style: directives get overwritten by the style attribute.
The same issue applies to class: directives.
Reproduction
<script>
let array =$state([{ a:0, b:0 }])
</script>
<div>
Change:
<buttontype="button"onclick={() =>array[0].a++}>`a`</button>
<buttontype="button"onclick={() =>array[0].b++}>`b`</button>
</div>
<div>
{#eacharrayasitem (item.a)}
<divstyle="z-index: {Number(item.b)};"style:background-color="#080">
{#iftrue}
it should stay green (a: {item.a}; b: {item.b})
{/if}
</div>
{/each}
</div>
<div>
<divstyle="z-index: {Number(array[0].b)};"style:background-color="#080">
{#iftrue}
it should stay green (a: {array[0].a}; b: {array[0].b})
{/if}
</div>
</div>
I believe it should merge the same way as in Svelte 4. That way, even if those effects were applied in a different order, at least different properties wouldn't overwrite. Although probably the calling order also should be fixed.
Describe the bug
Under certain conditions,
style:
directives get overwritten by thestyle
attribute, instead of being merged.In Svelte 4 they were always merged.
In Svelte 5 the
style
attribute is set first, thenstyle:
directives are applied onto it (from my observation). However, sometimes the order is incorrect andstyle:
directives get overwritten by thestyle
attribute.The same issue applies to
class:
directives.Reproduction
Link to REPL
This is the most minimal example I could make. It was spotted in a real project, while trying to migrate to Svelte 5.
Try pressing buttons in that order:
`a`
`b`
`a`
You will notice that:
`a`
everything works as expected`b`
the green background disappears`a`
the green background reappears only in the first blockHowever, they should always stay green.
Similar issue affects
class:
directives, as this REPL shows.In Svelte 4 I can see in the compiled code that the merging is done with the
set_style
function:But in Svelte 5 only
style:
directives are trying to merge, thestyle
attribute is set directly:I believe it should merge the same way as in Svelte 4. That way, even if those effects were applied in a different order, at least different properties wouldn't overwrite. Although probably the calling order also should be fixed.
Logs
No response
System Info
System: OS: macOS 14.5 CPU: (10) arm64 Apple M1 Pro Memory: 150.59 MB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.17.0 - /usr/local/bin/node npm: 10.8.2 - /usr/local/bin/npm pnpm: 8.9.0 - /usr/local/bin/pnpm bun: 1.0.14 - ~/.bun/bin/bun Browsers: Chrome: 129.0.6668.90 Chrome Canary: 131.0.6764.0 Safari: 17.5 Safari Technology Preview: 18.0
(using Vivaldi 6.9, not detected by the script)
The text was updated successfully, but these errors were encountered: