fix: remove nodes in boundary when work is pending and HMR is active (#17932)

Fixes
https://github.com/sveltejs/svelte/issues/17918#issuecomment-4054067024.

The issue here was that in `boundary.#render`, if `this.#pending_count >
0` we yoink the content out of the DOM so we can replace it with the
`pending` fragment. This works by taking everything from
`effect.nodes.start` to `effect.nodes.end` and putting it in a
`DocumentFragment`.

With HMR, that doesn't work, because the effect with the nodes is buried
inside the HMR effect. This fixes it.

Draft because I'd like to try this out in a few more places before
merging.
pull/17936/head
Rich Harris 3 days ago committed by GitHub
parent 32a48ed174
commit 1cd06451af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: remove nodes in boundary when work is pending and HMR is active

@ -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;
}

Loading…
Cancel
Save