Skip to content

Commit

Permalink
fix: correctly handle falsy values of style directives in SSR mode
Browse files Browse the repository at this point in the history
fixes #11044
  • Loading branch information
dummdidumm committed May 13, 2024
1 parent 81517a5 commit 55b7354
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/good-roses-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: correctly handle falsy values of style directives in SSR mode
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export function stringify(value) {
/** @param {Record<string, string>} style_object */
function style_object_to_string(style_object) {
return Object.keys(style_object)
.filter(/** @param {any} key */ (key) => style_object[key])
.filter(/** @param {any} key */ (key) => style_object[key] != null && style_object[key] !== '')
.map(/** @param {any} key */ (key) => `${key}: ${escape_html(style_object[key], true)};`)
.join(' ');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { test } from '../../test';

export default test({
html: `
<p style="--a: 0;"></p>
<p style="--b: false;"></p>
<p></p>
<p></p>
<p></p>
`
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p style:--a={0}></p>
<p style:--b={false}></p>
<p style:--c=""></p>
<p style:--d={undefined}></p>
<p style:--e={null}></p>

0 comments on commit 55b7354

Please sign in to comment.