8000 set_style optimization silently breaks on invalid style property value · Issue #5204 · sveltejs/svelte · GitHub
[go: up one dir, main page]

Skip to content
set_style optimization silently breaks on invalid style property value #5204
@trbrc

Description

@trbrc

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0