fix: correctly handle falsy values of style directives in SSR mode (#11583)

fixes #11044
pull/11595/head
Simon H 1 year ago committed by GitHub
parent a2bc0f5f7d
commit a0bdac8cd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: correctly handle falsy values of style directives in SSR mode

@ -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(' ');
}

@ -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>
`
});

@ -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>
Loading…
Cancel
Save