Home / File/ svelte-head.js — svelte Source File

svelte-head.js — svelte Source File

Architecture documentation for svelte-head.js, a javascript file in the svelte codebase. 10 imports, 0 dependents.

File javascript ClientRuntime Hydration 10 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  a88fcdad_d33c_c37e_dae2_b07d8bcb7300["svelte-head.js"]
  f3948b0d_b92a_0767_ba6c_832767f4e2bb["hydration.js"]
  a88fcdad_d33c_c37e_dae2_b07d8bcb7300 --> f3948b0d_b92a_0767_ba6c_832767f4e2bb
  40f27ad3_30bb_8f2a_3fb3_757088cf7428["set_hydrate_node"]
  a88fcdad_d33c_c37e_dae2_b07d8bcb7300 --> 40f27ad3_30bb_8f2a_3fb3_757088cf7428
  f5b61c69_d41c_bdb7_b931_5b8b3374332c["set_hydrating"]
  a88fcdad_d33c_c37e_dae2_b07d8bcb7300 --> f5b61c69_d41c_bdb7_b931_5b8b3374332c
  9a9bbc27_46b6_021c_6d77_f736ed4b40f0["operations.js"]
  a88fcdad_d33c_c37e_dae2_b07d8bcb7300 --> 9a9bbc27_46b6_021c_6d77_f736ed4b40f0
  ec54e18a_a454_5d8c_9e00_7bc16e4f49c4["create_text"]
  a88fcdad_d33c_c37e_dae2_b07d8bcb7300 --> ec54e18a_a454_5d8c_9e00_7bc16e4f49c4
  f3bd5a62_2879_ccbe_7046_712cbf9eeaab["get_first_child"]
  a88fcdad_d33c_c37e_dae2_b07d8bcb7300 --> f3bd5a62_2879_ccbe_7046_712cbf9eeaab
  4776c976_30bb_448d_921d_ee70a7fa0135["get_next_sibling"]
  a88fcdad_d33c_c37e_dae2_b07d8bcb7300 --> 4776c976_30bb_448d_921d_ee70a7fa0135
  1ae6fa4e_16ee_acdf_5e28_17eb0819fddb["effects.js"]
  a88fcdad_d33c_c37e_dae2_b07d8bcb7300 --> 1ae6fa4e_16ee_acdf_5e28_17eb0819fddb
  1bd7dd6f_4c22_6f44_9747_fc5ea0deaa7b["block"]
  a88fcdad_d33c_c37e_dae2_b07d8bcb7300 --> 1bd7dd6f_4c22_6f44_9747_fc5ea0deaa7b
  54c2bfce_50b6_b8cc_4371_e1e14f283fb3["constants"]
  a88fcdad_d33c_c37e_dae2_b07d8bcb7300 --> 54c2bfce_50b6_b8cc_4371_e1e14f283fb3
  style a88fcdad_d33c_c37e_dae2_b07d8bcb7300 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { TemplateNode } from '#client' */
import { hydrate_node, hydrating, set_hydrate_node, set_hydrating } from '../hydration.js';
import { create_text, get_first_child, get_next_sibling } from '../operations.js';
import { block } from '../../reactivity/effects.js';
import { COMMENT_NODE, HEAD_EFFECT } from '#client/constants';

/**
 * @param {string} hash
 * @param {(anchor: Node) => void} render_fn
 * @returns {void}
 */
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

Functions

Frequently Asked Questions

What does svelte-head.js do?
svelte-head.js is a source file in the svelte codebase, written in javascript. It belongs to the ClientRuntime domain, Hydration subdomain.
What functions are defined in svelte-head.js?
svelte-head.js defines 1 function(s): head.
What does svelte-head.js depend on?
svelte-head.js imports 10 module(s): block, constants, create_text, effects.js, get_first_child, get_next_sibling, hydration.js, operations.js, and 2 more.
Where is svelte-head.js in the architecture?
svelte-head.js is located at packages/svelte/src/internal/client/dom/blocks/svelte-head.js (domain: ClientRuntime, subdomain: Hydration, directory: packages/svelte/src/internal/client/dom/blocks).

Analyze Your Own Codebase

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

Try Supermodel Free