-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Describe the bug
Svelte tries to optimize style
attributes to use node.style.setProperty(...)
instead of node.setAttribute("style", ...)
in certain circumstances. The syntax makes it look like string interpolation, so you would expect it to always have the same result as interpolating the string and setting it as a regular attribute. But the optimization relies on some undocumented assumptions about how you would use these dynamic values, and breaks in some cases.
To Reproduce
Here is an example of some cases that breaks when using Svelte's curly brace syntax, but works with the corresponding JS string interpolation:
https://svelte.dev/repl/9d64d75662a04f049b7724cfe38bca73?version=3.24.0
Expected behavior
Given the lack of documentation or warnings, I simply expect the styles not to break, regardless of how I do the string interpolation.
As an acceptable alternative, the behavior could be documented, and compiling in dev
mode could warn when the optimization fails.
Severity
It's probably a niche case, and there are a variety of workarounds. Still, the current behavior could be very confusing and should probably documented.