diff --git a/.changeset/tangy-women-shout.md b/.changeset/tangy-women-shout.md new file mode 100644 index 0000000000..f62d799d93 --- /dev/null +++ b/.changeset/tangy-women-shout.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: remove nodes in boundary when work is pending and HMR is active diff --git a/packages/svelte/src/internal/client/dev/hmr.js b/packages/svelte/src/internal/client/dev/hmr.js index 9fa4e6ccbd..071901aafc 100644 --- a/packages/svelte/src/internal/client/dev/hmr.js +++ b/packages/svelte/src/internal/client/dev/hmr.js @@ -6,6 +6,8 @@ import { block, branch, destroy_effect } from '../reactivity/effects.js'; import { set, source } from '../reactivity/sources.js'; import { set_should_intro } from '../render.js'; import { get } from '../runtime.js'; +import { assign_nodes } from '../dom/template.js'; +import { create_comment } from '../dom/operations.js'; /** * @template {(anchor: Comment, props: any) => any} Component @@ -27,6 +29,13 @@ export function hmr(fn) { let ran = false; + // Surround the wrapped effects with comments and assign the nodes + // on the wrapping effects so the parent can properly do DOM operations. + let start = create_comment(); + let end = create_comment(); + + anchor.before(start); + block(() => { if (component === (component = get(current))) { return; @@ -61,6 +70,10 @@ export function hmr(fn) { anchor = hydrate_node; } + anchor.before(end); + + assign_nodes(start, end); + return instance; }