Home / Function/ head() — svelte Function Reference

head() — svelte Function Reference

Architecture documentation for the head() function in svelte-head.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  c320c890_09f2_296f_8dd7_94adba41673b["head()"]
  cce0bf01_356a_e774_2966_a29dd5a29d34["svelte-head.js"]
  c320c890_09f2_296f_8dd7_94adba41673b -->|defined in| cce0bf01_356a_e774_2966_a29dd5a29d34
  25afb65e_17ed_6e9f_a917_dff129f3865a["get_first_child()"]
  c320c890_09f2_296f_8dd7_94adba41673b -->|calls| 25afb65e_17ed_6e9f_a917_dff129f3865a
  1a9242e0_23b4_062a_7f9c_803eede65309["get_next_sibling()"]
  c320c890_09f2_296f_8dd7_94adba41673b -->|calls| 1a9242e0_23b4_062a_7f9c_803eede65309
  effb7ee2_82e1_b834_f896_29c2cf2d63dc["set_hydrating()"]
  c320c890_09f2_296f_8dd7_94adba41673b -->|calls| effb7ee2_82e1_b834_f896_29c2cf2d63dc
  d7b0d0d6_c987_d134_c836_a79463a70f8f["set_hydrate_node()"]
  c320c890_09f2_296f_8dd7_94adba41673b -->|calls| d7b0d0d6_c987_d134_c836_a79463a70f8f
  ea7448fe_496a_9c26_c283_5521e76e2488["create_text()"]
  c320c890_09f2_296f_8dd7_94adba41673b -->|calls| ea7448fe_496a_9c26_c283_5521e76e2488
  56735f42_3dab_c415_ff67_edbde8963f96["block()"]
  c320c890_09f2_296f_8dd7_94adba41673b -->|calls| 56735f42_3dab_c415_ff67_edbde8963f96
  style c320c890_09f2_296f_8dd7_94adba41673b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/internal/client/dom/blocks/svelte-head.js lines 12–59

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,
	// therefore we need to skip that when we detect that we're not in hydration mode.
	let previous_hydrate_node = null;
	let was_hydrating = hydrating;

	/** @type {Comment | Text} */
	var anchor;

	if (hydrating) {
		previous_hydrate_node = hydrate_node;

		var head_anchor = 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 (
			head_anchor !== null &&
			(head_anchor.nodeType !== COMMENT_NODE || /** @type {Comment} */ (head_anchor).data !== hash)
		) {
			head_anchor = get_next_sibling(head_anchor);
		}

		// If we can't find an opening hydration marker, skip hydration (this can happen
		// if a framework rendered body but not head content)
		if (head_anchor === null) {
			set_hydrating(false);
		} else {
			var start = /** @type {TemplateNode} */ (get_next_sibling(head_anchor));
			head_anchor.remove(); // in case this component is repeated

			set_hydrate_node(start);
		}
	}

	if (!hydrating) {
		anchor = document.head.appendChild(create_text());
	}

	try {
		block(() => render_fn(anchor), HEAD_EFFECT);
	} finally {
		if (was_hydrating) {
			set_hydrating(true);
			set_hydrate_node(/** @type {TemplateNode} */ (previous_hydrate_node));
		}
	}
}

Domain

Subdomains

Frequently Asked Questions

What does head() do?
head() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/dom/blocks/svelte-head.js.
Where is head() defined?
head() is defined in packages/svelte/src/internal/client/dom/blocks/svelte-head.js at line 12.
What does head() call?
head() calls 6 function(s): block, create_text, get_first_child, get_next_sibling, set_hydrate_node, set_hydrating.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free