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

@ -41,8 +41,6 @@ const LIS_BLOCK = -2;
* @returns {void} * @returns {void}
*/ */
function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, reconcile_fn) { 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} */ /** @type {import('#client').EachBlock} */
const block = { const block = {
// dom // 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) 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} */ /** @type {import('#client').Effect | null} */
let fallback = null; let fallback = null;

@ -73,33 +73,26 @@ export function get_hydration_fragment(node, insert_text = false) {
} }
/** /**
* @param {Text | Comment | Element} anchor_node * @param {Node} node
* @param {boolean} [is_controlled]
* @returns {void} * @returns {void}
*/ */
export function hydrate_block_anchor(anchor_node, is_controlled) { export function hydrate_block_anchor(node) {
if (hydrating) { if (!hydrating) return;
/** @type {Node} */
let target_node = anchor_node;
if (is_controlled) { if (node.nodeType === 8) {
target_node = /** @type {Node} */ (target_node.firstChild);
}
if (target_node.nodeType === 8) {
// @ts-ignore // @ts-ignore
let fragment = target_node.$$fragment; let fragment = node.$$fragment;
if (fragment === undefined) { if (fragment === undefined) {
fragment = get_hydration_fragment(target_node); fragment = get_hydration_fragment(node);
} else { } else {
schedule_task(() => { schedule_task(() => {
// @ts-expect-error clean up memory // @ts-expect-error clean up memory
target_node.$$fragment = undefined; node.$$fragment = undefined;
}); });
} }
set_current_hydration_fragment(fragment); set_current_hydration_fragment(fragment);
} else { } 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]); 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) { function open_template(is_fragment, use_clone_node, anchor, template_element_fn) {
if (hydrating) { if (hydrating) {
if (anchor !== null) { if (anchor !== null) {
hydrate_block_anchor(anchor, false); hydrate_block_anchor(anchor);
} }
// In ssr+hydration optimization mode, we might remove the template_element, // In ssr+hydration optimization mode, we might remove the template_element,
// so we need to is_fragment flag to properly handle hydrated content accordingly. // so we need to is_fragment flag to properly handle hydrated content accordingly.

Loading…
Cancel
Save