|
|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import { hydrate_nodes, hydrating, set_hydrate_nodes } from '../hydration.js';
|
|
|
|
|
/** @import { TemplateNode } from '#client' */
|
|
|
|
|
import { hydrate_node, hydrating, set_hydrate_node } from '../hydration.js';
|
|
|
|
|
import { empty } from '../operations.js';
|
|
|
|
|
import { block } from '../../reactivity/effects.js';
|
|
|
|
|
import { HYDRATION_START } from '../../../../constants.js';
|
|
|
|
|
@ -14,34 +15,34 @@ export function reset_head_anchor() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {(anchor: Node) => import('#client').Dom | void} render_fn
|
|
|
|
|
* @param {(anchor: Node) => void} render_fn
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
|
|
|
|
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_nodes = null;
|
|
|
|
|
let previous_hydrate_node = null;
|
|
|
|
|
let was_hydrating = hydrating;
|
|
|
|
|
|
|
|
|
|
/** @type {Comment | Text} */
|
|
|
|
|
var anchor;
|
|
|
|
|
|
|
|
|
|
if (hydrating) {
|
|
|
|
|
previous_hydrate_nodes = hydrate_nodes;
|
|
|
|
|
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.
|
|
|
|
|
if (head_anchor === undefined) {
|
|
|
|
|
head_anchor = /** @type {import('#client').TemplateNode} */ (document.head.firstChild);
|
|
|
|
|
head_anchor = /** @type {TemplateNode} */ (document.head.firstChild);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (
|
|
|
|
|
head_anchor.nodeType !== 8 ||
|
|
|
|
|
/** @type {Comment} */ (head_anchor).data !== HYDRATION_START
|
|
|
|
|
) {
|
|
|
|
|
head_anchor = /** @type {import('#client').TemplateNode} */ (head_anchor.nextSibling);
|
|
|
|
|
head_anchor = /** @type {TemplateNode} */ (head_anchor.nextSibling);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
head_anchor = /** @type {import('#client').TemplateNode} */ (head_anchor.nextSibling);
|
|
|
|
|
head_anchor = /** @type {TemplateNode} */ (head_anchor.nextSibling);
|
|
|
|
|
} else {
|
|
|
|
|
anchor = document.head.appendChild(empty());
|
|
|
|
|
}
|
|
|
|
|
@ -50,7 +51,7 @@ export function head(render_fn) {
|
|
|
|
|
block(() => render_fn(anchor), HEAD_EFFECT);
|
|
|
|
|
} finally {
|
|
|
|
|
if (was_hydrating) {
|
|
|
|
|
set_hydrate_nodes(/** @type {import('#client').TemplateNode[]} */ (previous_hydrate_nodes));
|
|
|
|
|
set_hydrate_node(/** @type {TemplateNode} */ (previous_hydrate_node));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|