chore: remove redundant hydration code (#9698)

pull/9720/head
Dominic Gannaway 2 years ago committed by GitHub
parent e3dc185a4c
commit 2e461eb314
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
chore: remove redundant hydration code

@ -1,5 +1,7 @@
// Handle hydration
import { schedule_task } from './runtime';
/** @type {null | Array<Text | Comment | Element>} */
export let current_hydration_fragment = null;
@ -68,12 +70,16 @@ export function hydrate_block_anchor(anchor_node, is_controlled) {
let fragment = target_node.$$fragment;
if (fragment === undefined) {
fragment = get_hydration_fragment(target_node);
// @ts-ignore remove to prevent memory leaks
target_node.$$fragment = undefined;
} else {
schedule_task(() => {
// @ts-expect-error clean up memory
target_node.$$fragment = undefined;
});
}
set_current_hydration_fragment(fragment);
} else {
set_current_hydration_fragment([/** @type {Element} */ (target_node.firstChild)]);
const first_child = /** @type {Element | null} */ (target_node.firstChild);
set_current_hydration_fragment(first_child === null ? [] : [first_child]);
}
}
}

@ -61,8 +61,7 @@ import {
push,
current_component_context,
pop,
schedule_task,
managed_render_effect
schedule_task
} from './runtime.js';
import {
current_hydration_fragment,
@ -211,8 +210,10 @@ function close_template(dom, is_fragment, anchor) {
? dom
: /** @type {import('./types.js').TemplateNode[]} */ (Array.from(dom.childNodes))
: dom;
if (anchor !== null && current_hydration_fragment === null) {
insert(current, null, anchor);
if (anchor !== null) {
if (current_hydration_fragment === null) {
insert(current, null, anchor);
}
}
block.d = current;
}
@ -1396,9 +1397,7 @@ function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn) {
} else if (current_hydration_fragment !== null) {
const comment_text = /** @type {Comment} */ (current_hydration_fragment?.[0])?.data;
if (
(!comment_text &&
// Can happen when a svelte:element that is turned into a void element has an if block inside
current_hydration_fragment[0] !== null) ||
!comment_text ||
(comment_text === 'ssr:if:true' && !result) ||
(comment_text === 'ssr:if:false' && result)
) {

Loading…
Cancel
Save