pull/10798/head
Rich Harris 2 years ago
parent c55b143eab
commit 4d6aa3026c

@ -41,8 +41,6 @@ const LIS_BLOCK = -2;
* @returns {void}
*/
function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, reconcile_fn) {
const is_controlled = (flags & EACH_IS_CONTROLLED) !== 0;
/** @type {import('#client').EachBlock} */
const block = {
// dom
@ -56,7 +54,8 @@ function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, re
p: /** @type {import('#client').Block} */ (current_block)
};
hydrate_block_anchor(anchor_node, is_controlled);
const is_controlled = (flags & EACH_IS_CONTROLLED) !== 0;
hydrate_block_anchor(is_controlled ? /** @type {Node} */ (anchor_node.firstChild) : anchor_node);
/** @type {import('#client').Effect | null} */
let fallback = null;

@ -73,33 +73,26 @@ export function get_hydration_fragment(node, insert_text = false) {
}
/**
* @param {Text | Comment | Element} anchor_node
* @param {boolean} [is_controlled]
* @param {Node} node
* @returns {void}
*/
export function hydrate_block_anchor(anchor_node, is_controlled) {
if (hydrating) {
/** @type {Node} */
let target_node = anchor_node;
export function hydrate_block_anchor(node) {
if (!hydrating) return;
if (is_controlled) {
target_node = /** @type {Node} */ (target_node.firstChild);
}
if (target_node.nodeType === 8) {
if (node.nodeType === 8) {
// @ts-ignore
let fragment = target_node.$$fragment;
let fragment = node.$$fragment;
if (fragment === undefined) {
fragment = get_hydration_fragment(target_node);
fragment = get_hydration_fragment(node);
} else {
schedule_task(() => {
// @ts-expect-error clean up memory
target_node.$$fragment = undefined;
node.$$fragment = undefined;
});
}
set_current_hydration_fragment(fragment);
} else {
const first_child = /** @type {Element | null} */ (target_node.firstChild);
const first_child = /** @type {Element | null} */ (node.firstChild);
set_current_hydration_fragment(first_child === null ? [] : [first_child]);
}
}
}

@ -90,7 +90,7 @@ export function svg_template_with_script(svg, return_fragment) {
function open_template(is_fragment, use_clone_node, anchor, template_element_fn) {
if (hydrating) {
if (anchor !== null) {
hydrate_block_anchor(anchor, false);
hydrate_block_anchor(anchor);
}
// In ssr+hydration optimization mode, we might remove the template_element,
// so we need to is_fragment flag to properly handle hydrated content accordingly.

Loading…
Cancel
Save