Skip to content

Commit b70d12c

Browse files
trueadmadigubaRich-Harris
authored
fix: render undefined html as the empty string (#13092)
Fix #13069 --------- Co-authored-by: adiGuba <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent d776e52 commit b70d12c

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

.changeset/eighty-mails-develop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: render undefined html as the empty string

packages/svelte/src/internal/client/dom/blocks/html.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function html(node, get_value, svg, mathml, skip_warning) {
5050
var effect;
5151

5252
block(() => {
53-
if (value === (value = get_value())) {
53+
if (value === (value = get_value() ?? '')) {
5454
if (hydrating) {
5555
hydrate_next();
5656
}

packages/svelte/src/internal/server/blocks/html.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { hash } from '../../../utils.js';
55
* @param {string} value
66
*/
77
export function html(value) {
8-
var open = DEV ? `<!--${hash(String(value ?? ''))}-->` : '<!---->';
9-
return `${open}${value}<!---->`;
8+
var html = String(value ?? '');
9+
var open = DEV ? `<!--${hash(html)}-->` : '<!---->';
10+
return open + html + '<!---->';
1011
}

packages/svelte/tests/runtime-legacy/samples/binding-contenteditable-html-initial/_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default test({
1515

1616
ssrHtml: `
1717
<editor contenteditable="true"><b>world</b></editor>
18-
<p>hello null</p>
18+
<p>hello </p>
1919
`,
2020

2121
async test({ assert, component, target, window }) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: ''
5+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{@html undefined}

0 commit comments

Comments
 (0)