|
|
|
@ -3,22 +3,13 @@ import { hydrate_node, hydrating, set_hydrate_node, set_hydrating } from '../hyd
|
|
|
|
import { create_text, get_first_child, get_next_sibling } from '../operations.js';
|
|
|
|
import { create_text, get_first_child, get_next_sibling } from '../operations.js';
|
|
|
|
import { block } from '../../reactivity/effects.js';
|
|
|
|
import { block } from '../../reactivity/effects.js';
|
|
|
|
import { COMMENT_NODE, HEAD_EFFECT } from '#client/constants';
|
|
|
|
import { COMMENT_NODE, HEAD_EFFECT } from '#client/constants';
|
|
|
|
import { HYDRATION_START } from '../../../../constants.js';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @type {Node | undefined}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
let head_anchor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function reset_head_anchor() {
|
|
|
|
|
|
|
|
head_anchor = undefined;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param {string} hash
|
|
|
|
* @param {(anchor: Node) => void} render_fn
|
|
|
|
* @param {(anchor: Node) => void} render_fn
|
|
|
|
* @returns {void}
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function head(render_fn) {
|
|
|
|
export function head(hash, render_fn) {
|
|
|
|
// The head function may be called after the first hydration pass and ssr comment nodes may still be present,
|
|
|
|
// 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.
|
|
|
|
// therefore we need to skip that when we detect that we're not in hydration mode.
|
|
|
|
let previous_hydrate_node = null;
|
|
|
|
let previous_hydrate_node = null;
|
|
|
|
@ -30,15 +21,13 @@ export function head(render_fn) {
|
|
|
|
if (hydrating) {
|
|
|
|
if (hydrating) {
|
|
|
|
previous_hydrate_node = hydrate_node;
|
|
|
|
previous_hydrate_node = hydrate_node;
|
|
|
|
|
|
|
|
|
|
|
|
// There might be multiple head blocks in our app, so we need to account for each one needing independent hydration.
|
|
|
|
var head_anchor = /** @type {TemplateNode} */ (get_first_child(document.head));
|
|
|
|
if (head_anchor === undefined) {
|
|
|
|
|
|
|
|
head_anchor = /** @type {TemplateNode} */ (get_first_child(document.head));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// There might be multiple head blocks in our app, and they could have been
|
|
|
|
|
|
|
|
// rendered in an arbitrary order — find one corresponding to this component
|
|
|
|
while (
|
|
|
|
while (
|
|
|
|
head_anchor !== null &&
|
|
|
|
head_anchor !== null &&
|
|
|
|
(head_anchor.nodeType !== COMMENT_NODE ||
|
|
|
|
(head_anchor.nodeType !== COMMENT_NODE || /** @type {Comment} */ (head_anchor).data !== hash)
|
|
|
|
/** @type {Comment} */ (head_anchor).data !== HYDRATION_START)
|
|
|
|
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
head_anchor = /** @type {TemplateNode} */ (get_next_sibling(head_anchor));
|
|
|
|
head_anchor = /** @type {TemplateNode} */ (get_next_sibling(head_anchor));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -48,7 +37,10 @@ export function head(render_fn) {
|
|
|
|
if (head_anchor === null) {
|
|
|
|
if (head_anchor === null) {
|
|
|
|
set_hydrating(false);
|
|
|
|
set_hydrating(false);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
head_anchor = set_hydrate_node(/** @type {TemplateNode} */ (get_next_sibling(head_anchor)));
|
|
|
|
var start = /** @type {TemplateNode} */ (get_next_sibling(head_anchor));
|
|
|
|
|
|
|
|
head_anchor.remove(); // in case this component is repeated
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set_hydrate_node(start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -61,7 +53,6 @@ export function head(render_fn) {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if (was_hydrating) {
|
|
|
|
if (was_hydrating) {
|
|
|
|
set_hydrating(true);
|
|
|
|
set_hydrating(true);
|
|
|
|
head_anchor = hydrate_node; // so that next head block starts from the correct node
|
|
|
|
|
|
|
|
set_hydrate_node(/** @type {TemplateNode} */ (previous_hydrate_node));
|
|
|
|
set_hydrate_node(/** @type {TemplateNode} */ (previous_hydrate_node));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|