diff --git a/.changeset/long-coats-fry.md b/.changeset/long-coats-fry.md new file mode 100644 index 0000000000..936aae8ff6 --- /dev/null +++ b/.changeset/long-coats-fry.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: correctly set anchor inside HMR block diff --git a/packages/svelte/src/internal/client/dev/hmr.js b/packages/svelte/src/internal/client/dev/hmr.js index 0b511ee841..ee5e08c0b1 100644 --- a/packages/svelte/src/internal/client/dev/hmr.js +++ b/packages/svelte/src/internal/client/dev/hmr.js @@ -1,6 +1,7 @@ -/** @import { Source, Effect } from '#client' */ +/** @import { Source, Effect, TemplateNode } from '#client' */ import { FILENAME, HMR } from '../../../constants.js'; import { EFFECT_TRANSPARENT } from '../constants.js'; +import { hydrate_node, hydrating } from '../dom/hydration.js'; import { block, branch, destroy_effect } from '../reactivity/effects.js'; import { source } from '../reactivity/sources.js'; import { set_should_intro } from '../render.js'; @@ -13,7 +14,7 @@ import { get } from '../runtime.js'; */ export function hmr(original, get_source) { /** - * @param {Comment} anchor + * @param {TemplateNode} anchor * @param {any} props */ function wrapper(anchor, props) { @@ -53,6 +54,10 @@ export function hmr(original, get_source) { ran = true; + if (hydrating) { + anchor = hydrate_node; + } + return instance; }