Skip to content

Commit 2e461eb

Browse files
authored
chore: remove redundant hydration code (#9698)
1 parent e3dc185 commit 2e461eb

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

.changeset/sour-forks-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: remove redundant hydration code

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Handle hydration
22

3+
import { schedule_task } from './runtime';
4+
35
/** @type {null | Array<Text | Comment | Element>} */
46
export let current_hydration_fragment = null;
57

@@ -68,12 +70,16 @@ export function hydrate_block_anchor(anchor_node, is_controlled) {
6870
let fragment = target_node.$$fragment;
6971
if (fragment === undefined) {
7072
fragment = get_hydration_fragment(target_node);
71-
// @ts-ignore remove to prevent memory leaks
72-
target_node.$$fragment = undefined;
73+
} else {
74+
schedule_task(() => {
75+
// @ts-expect-error clean up memory
76+
target_node.$$fragment = undefined;
77+
});
7378
}
7479
set_current_hydration_fragment(fragment);
7580
} else {
76-
set_current_hydration_fragment([/** @type {Element} */ (target_node.firstChild)]);
81+
const first_child = /** @type {Element | null} */ (target_node.firstChild);
82+
set_current_hydration_fragment(first_child === null ? [] : [first_child]);
7783
}
7884
}
7985
}

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

Lines changed: 6 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,
@@ -211,8 +210,10 @@ 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+
}
216217
}
217218
block.d = current;
218219
}
@@ -1396,9 +1397,7 @@ function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn) {
13961397
} else if (current_hydration_fragment !== null) {
13971398
const comment_text = /** @type {Comment} */ (current_hydration_fragment?.[0])?.data;
13981399
if (
1399-
(!comment_text &&
1400-
// Can happen when a svelte:element that is turned into a void element has an if block inside
1401-
current_hydration_fragment[0] !== null) ||
1400+
!comment_text ||
14021401
(comment_text === 'ssr:if:true' && !result) ||
14031402
(comment_text === 'ssr:if:false' && result)
14041403
) {

0 commit comments

Comments
 (0)