Skip to content

Commit 5b5df3d

Browse files
committed
cleanup memory
1 parent c77b0e8 commit 5b5df3d

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

packages/svelte/src/internal/client/render.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ import {
6161
push,
6262
current_component_context,
6363
pop,
64-
schedule_task,
65-
managed_render_effect
64+
schedule_task
6665
} from './runtime.js';
6766
import {
6867
current_hydration_fragment,
@@ -199,7 +198,7 @@ export function comment(anchor) {
199198
/**
200199
* @param {Element | Text} dom
201200
* @param {boolean} is_fragment
202-
* @param {null | Text | Comment | Element} anchor
201+
* @param {null | ((Text | Comment | Element) & {$$fragment: undefined | Node[]})} anchor
203202
* @returns {void}
204203
*/
205204
function close_template(dom, is_fragment, anchor) {
@@ -211,14 +210,18 @@ function close_template(dom, is_fragment, anchor) {
211210
? dom
212211
: /** @type {import('./types.js').TemplateNode[]} */ (Array.from(dom.childNodes))
213212
: dom;
214-
if (anchor !== null && current_hydration_fragment === null) {
215-
insert(current, null, anchor);
213+
if (anchor !== null) {
214+
if (current_hydration_fragment === null) {
215+
insert(current, null, anchor);
216+
} else {
217+
cleanup_hyration_node(anchor);
218+
}
216219
}
217220
block.d = current;
218221
}
219222

220223
/**
221-
* @param {null | Text | Comment | Element} anchor
224+
* @param {null | ((Text | Comment | Element) & {$$fragment: undefined | Node[]})} anchor
222225
* @param {Element | Text} dom
223226
* @returns {void}
224227
*/
@@ -227,7 +230,7 @@ export function close(anchor, dom) {
227230
}
228231

229232
/**
230-
* @param {null | Text | Comment | Element} anchor
233+
* @param {null | ((Text | Comment | Element) & {$$fragment: undefined | Node[]})} anchor
231234
* @param {Element | Text} dom
232235
* @returns {void}
233236
*/
@@ -1341,6 +1344,20 @@ export function slot(anchor_node, slot_fn, slot_props, fallback_fn) {
13411344
} else {
13421345
slot_fn(anchor_node, slot_props);
13431346
}
1347+
cleanup_hyration_node(anchor_node);
1348+
}
1349+
1350+
/**
1351+
*
1352+
* @param {Element | Comment} node
1353+
*/
1354+
function cleanup_hyration_node(node) {
1355+
// Let's ensure we don't leak the hydration fragment
1356+
// @ts-expect-error internal field
1357+
if (node.$$fragment) {
1358+
// @ts-expect-error internal field
1359+
node.$$fragment = undefined;
1360+
}
13441361
}
13451362

13461363
/**
@@ -1472,6 +1489,7 @@ function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn) {
14721489
destroy_signal(alternate_effect);
14731490
});
14741491
block.e = if_effect;
1492+
cleanup_hyration_node(anchor_node);
14751493
}
14761494
export { if_block as if };
14771495

@@ -1615,6 +1633,7 @@ export function element(anchor_node, tag_fn, render_fn, is_svg = false) {
16151633
}
16161634
destroy_signal(render_effect_signal);
16171635
});
1636+
cleanup_hyration_node(anchor_node);
16181637
block.e = element_effect;
16191638
}
16201639

@@ -1732,6 +1751,7 @@ export function component(anchor_node, component_fn, render_fn) {
17321751
render = render.p;
17331752
}
17341753
});
1754+
cleanup_hyration_node(anchor_node);
17351755
block.e = component_effect;
17361756
}
17371757

@@ -1899,6 +1919,7 @@ function await_block(anchor_node, input, pending_fn, then_fn, catch_fn) {
18991919
render = render.p;
19001920
}
19011921
});
1922+
cleanup_hyration_node(anchor_node);
19021923
block.e = await_effect;
19031924
}
19041925
export { await_block as await };
@@ -2015,6 +2036,7 @@ export function key(anchor_node, key, render_fn) {
20152036
render = render.p;
20162037
}
20172038
});
2039+
cleanup_hyration_node(anchor_node);
20182040
block.e = key_effect;
20192041
}
20202042

@@ -2270,6 +2292,7 @@ function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, re
22702292
reconcile_fn([], block, anchor_node, is_controlled, render_fn, flags, false, keys);
22712293
destroy_signal(/** @type {import('./types.js').EffectSignal} */ (render));
22722294
});
2295+
cleanup_hyration_node(anchor_node);
22732296
block.e = each;
22742297
}
22752298

0 commit comments

Comments
 (0)