remove hydrate_end

pull/11690/head
Rich Harris 2 years ago
parent 3cdca108b3
commit d9f9755b38

@ -1,10 +1,4 @@
import {
hydrate_anchor,
hydrate_start,
hydrate_end,
hydrating,
set_hydrate_nodes
} from '../hydration.js';
import { hydrate_anchor, hydrate_start, hydrating, set_hydrate_nodes } from '../hydration.js';
import { empty } from '../operations.js';
import { block } from '../../reactivity/effects.js';
import { HYDRATION_START } from '../../../../constants.js';
@ -26,7 +20,6 @@ export function head(render_fn) {
// The head function may be called after the first hydration pass and ssr comment nodes may still be present,
// therefore we need to skip that when we detect that we're not in hydration mode.
let previous_hydrate_start = null;
let previous_hydrate_end = null;
let was_hydrating = hydrating;
/** @type {Comment | Text} */
@ -34,7 +27,6 @@ export function head(render_fn) {
if (hydrating) {
previous_hydrate_start = hydrate_start;
previous_hydrate_end = hydrate_end;
// There might be multiple head blocks in our app, so we need to account for each one needing independent hydration.
if (head_anchor === undefined) {
@ -58,10 +50,7 @@ export function head(render_fn) {
block(() => render_fn(anchor));
} finally {
if (was_hydrating) {
set_hydrate_nodes(
/** @type {import('#client').TemplateNode} */ (previous_hydrate_start),
/** @type {import('#client').TemplateNode} */ (previous_hydrate_end)
);
set_hydrate_nodes(/** @type {import('#client').TemplateNode} */ (previous_hydrate_start));
}
}
}

@ -17,22 +17,16 @@ export function set_hydrating(value) {
/** @type {import('#client').TemplateNode} */
export let hydrate_start = /** @type {any} */ (null);
/** @type {import('#client').TemplateNode} */
export let hydrate_end = /** @type {any} */ (null);
/**
* @param {import('#client').TemplateNode} start
* @param {import('#client').TemplateNode} end
*/
export function set_hydrate_nodes(start, end) {
export function set_hydrate_nodes(start) {
hydrate_start = start;
hydrate_end = end;
}
/**
* This function is only called when `hydrating` is true. If passed a `<!--[-->` opening
* hydration marker, it finds the corresponding closing marker and sets `hydrate_start`
* and `hydrate_end` to the content inside, before returning the closing marker.
* hydration marker, it sets `hydrate_start` to be the next node and returns the closing marker
* @param {Node} node
* @returns {Node}
*/
@ -69,7 +63,6 @@ export function hydrate_anchor(node) {
}
start ??= /** @type {import('#client').TemplateNode} */ (current);
hydrate_end = /** @type {import('#client').TemplateNode} */ (current);
}
let location;
@ -87,5 +80,24 @@ export function hydrate_anchor(node) {
}
export function remove_hydrate_nodes() {
remove_nodes(hydrate_start, hydrate_end);
/** @type {import('#client').TemplateNode | null} */
var node = hydrate_start;
var depth = 0;
while (node) {
if (node.nodeType === 8) {
var data = /** @type {Comment} */ (node).data;
if (data === HYDRATION_START) {
depth += 1;
} else if (data[0] === HYDRATION_END) {
if (depth === 0) return;
depth -= 1;
}
}
var next = /** @type {import('#client').TemplateNode | null} */ (node.nextSibling);
node.remove();
node = next;
}
}

@ -5,7 +5,6 @@ import { flush_sync, push, pop, current_component_context } from './runtime.js';
import { effect_root, branch } from './reactivity/effects.js';
import {
hydrate_anchor,
hydrate_end,
hydrate_start,
hydrating,
set_hydrate_nodes,
@ -131,7 +130,6 @@ export function hydrate(component, options) {
const target = options.target;
const previous_hydrate_start = hydrate_start;
const previous_hydrate_end = hydrate_end;
try {
// Don't flush previous effects to ensure order of outer effects stays consistent
@ -176,7 +174,7 @@ export function hydrate(component, options) {
throw error;
} finally {
set_hydrating(!!previous_hydrate_start);
set_hydrate_nodes(previous_hydrate_start, previous_hydrate_end);
set_hydrate_nodes(previous_hydrate_start);
reset_head_anchor();
}
}

Loading…
Cancel
Save