diff --git a/.changeset/shiny-wombats-argue.md b/.changeset/shiny-wombats-argue.md new file mode 100644 index 0000000000..b35f1cf304 --- /dev/null +++ b/.changeset/shiny-wombats-argue.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: correctly hydrate empty raw blocks diff --git a/packages/svelte/src/internal/client/dom/blocks/html.js b/packages/svelte/src/internal/client/dom/blocks/html.js index cdfa1baa71..1240352ea0 100644 --- a/packages/svelte/src/internal/client/dom/blocks/html.js +++ b/packages/svelte/src/internal/client/dom/blocks/html.js @@ -46,15 +46,20 @@ export function html(node, get_value, svg, mathml, skip_warning) { var value = ''; - /** @type {Effect | null} */ + /** @type {Effect | undefined} */ var effect; block(() => { - if (value === (value = get_value())) return; + if (value === (value = get_value())) { + if (hydrating) { + hydrate_next(); + } + return; + } - if (effect) { + if (effect !== undefined) { destroy_effect(effect); - effect = null; + effect = undefined; } if (value === '') return; diff --git a/packages/svelte/tests/hydration/samples/raw-empty/_config.js b/packages/svelte/tests/hydration/samples/raw-empty/_config.js new file mode 100644 index 0000000000..5f4d5bebb1 --- /dev/null +++ b/packages/svelte/tests/hydration/samples/raw-empty/_config.js @@ -0,0 +1,15 @@ +import { test } from '../../test'; + +export default test({ + server_props: { + html: '
' + }, + + props: { + html: '' + }, + + test(assert, target) { + assert.htmlEqual(target.innerHTML, ''); + } +}); diff --git a/packages/svelte/tests/hydration/samples/raw-empty/main.svelte b/packages/svelte/tests/hydration/samples/raw-empty/main.svelte new file mode 100644 index 0000000000..c7ff3d05c9 --- /dev/null +++ b/packages/svelte/tests/hydration/samples/raw-empty/main.svelte @@ -0,0 +1 @@ +