diff --git a/.changeset/four-papayas-turn.md b/.changeset/four-papayas-turn.md new file mode 100644 index 0000000000..ceed9bdf71 --- /dev/null +++ b/.changeset/four-papayas-turn.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: reset hydrate node after `hydrate(...)` diff --git a/packages/svelte/src/internal/client/render.js b/packages/svelte/src/internal/client/render.js index 73798d1b8a..8510d49dab 100644 --- a/packages/svelte/src/internal/client/render.js +++ b/packages/svelte/src/internal/client/render.js @@ -119,6 +119,7 @@ export function hydrate(component, options) { options.intro = options.intro ?? false; const target = options.target; const was_hydrating = hydrating; + const previous_hydrate_node = hydrate_node; try { // Don't flush previous effects to ensure order of outer effects stays consistent @@ -175,6 +176,7 @@ export function hydrate(component, options) { throw error; } finally { set_hydrating(was_hydrating); + set_hydrate_node(previous_hydrate_node); reset_head_anchor(); } } diff --git a/packages/svelte/tests/runtime-legacy/shared.ts b/packages/svelte/tests/runtime-legacy/shared.ts index 8769be7504..640e9a49ee 100644 --- a/packages/svelte/tests/runtime-legacy/shared.ts +++ b/packages/svelte/tests/runtime-legacy/shared.ts @@ -35,6 +35,7 @@ export interface RuntimeTest = Record; props?: Props; + server_props?: Props; before_test?: () => void; after_test?: () => void; test?: (args: { @@ -256,7 +257,9 @@ async function run_test_variant( config.before_test?.(); // ssr into target const SsrSvelteComponent = (await import(`${cwd}/_output/server/main.svelte.js`)).default; - const { html, head } = render(SsrSvelteComponent, { props: config.props || {} }); + const { html, head } = render(SsrSvelteComponent, { + props: config.server_props ?? config.props ?? {} + }); fs.writeFileSync(`${cwd}/_output/rendered.html`, html); target.innerHTML = html; diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-raw-component/Child.svelte b/packages/svelte/tests/runtime-runes/samples/snippet-raw-component/Child.svelte new file mode 100644 index 0000000000..d61a532607 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-raw-component/Child.svelte @@ -0,0 +1,7 @@ + + + diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-raw-component/_config.js b/packages/svelte/tests/runtime-runes/samples/snippet-raw-component/_config.js new file mode 100644 index 0000000000..a13f1eb29e --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-raw-component/_config.js @@ -0,0 +1,21 @@ +import { flushSync } from 'svelte'; +import { test } from '../../test'; + +export default test({ + props: { + browser: true + }, + + server_props: { + browser: false + }, + + html: `
`, + + test({ target, assert }) { + const button = target.querySelector('button'); + + flushSync(() => button?.click()); + assert.htmlEqual(target.innerHTML, `
`); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-raw-component/main.svelte b/packages/svelte/tests/runtime-runes/samples/snippet-raw-component/main.svelte new file mode 100644 index 0000000000..697e6d3b75 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-raw-component/main.svelte @@ -0,0 +1,20 @@ + + +{@render hello()}