diff --git a/.changeset/eighty-mails-develop.md b/.changeset/eighty-mails-develop.md
new file mode 100644
index 0000000000..94eee085f7
--- /dev/null
+++ b/.changeset/eighty-mails-develop.md
@@ -0,0 +1,5 @@
+---
+'svelte': patch
+---
+
+fix: render undefined html as the empty string
diff --git a/packages/svelte/src/internal/client/dom/blocks/html.js b/packages/svelte/src/internal/client/dom/blocks/html.js
index 1240352ea0..aa13336b29 100644
--- a/packages/svelte/src/internal/client/dom/blocks/html.js
+++ b/packages/svelte/src/internal/client/dom/blocks/html.js
@@ -50,7 +50,7 @@ export function html(node, get_value, svg, mathml, skip_warning) {
var effect;
block(() => {
- if (value === (value = get_value())) {
+ if (value === (value = get_value() ?? '')) {
if (hydrating) {
hydrate_next();
}
diff --git a/packages/svelte/src/internal/server/blocks/html.js b/packages/svelte/src/internal/server/blocks/html.js
index 09efbc78fe..c8ef5d81b4 100644
--- a/packages/svelte/src/internal/server/blocks/html.js
+++ b/packages/svelte/src/internal/server/blocks/html.js
@@ -5,6 +5,7 @@ import { hash } from '../../../utils.js';
* @param {string} value
*/
export function html(value) {
- var open = DEV ? `` : '';
- return `${open}${value}`;
+ var html = String(value ?? '');
+ var open = DEV ? `` : '';
+ return open + html + '';
}
diff --git a/packages/svelte/tests/runtime-legacy/samples/binding-contenteditable-html-initial/_config.js b/packages/svelte/tests/runtime-legacy/samples/binding-contenteditable-html-initial/_config.js
index 38cf0ac542..46984df0c2 100644
--- a/packages/svelte/tests/runtime-legacy/samples/binding-contenteditable-html-initial/_config.js
+++ b/packages/svelte/tests/runtime-legacy/samples/binding-contenteditable-html-initial/_config.js
@@ -15,7 +15,7 @@ export default test({
ssrHtml: `
hello null
+hello
`, async test({ assert, component, target, window }) { diff --git a/packages/svelte/tests/runtime-runes/samples/html-tag-empty/_config.js b/packages/svelte/tests/runtime-runes/samples/html-tag-empty/_config.js new file mode 100644 index 0000000000..653ccc2192 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/html-tag-empty/_config.js @@ -0,0 +1,5 @@ +import { test } from '../../test'; + +export default test({ + html: '' +}); diff --git a/packages/svelte/tests/runtime-runes/samples/html-tag-empty/main.svelte b/packages/svelte/tests/runtime-runes/samples/html-tag-empty/main.svelte new file mode 100644 index 0000000000..d03d2a46c2 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/html-tag-empty/main.svelte @@ -0,0 +1 @@ +{@html undefined}