Home / Function/ html() — svelte Function Reference

html() — svelte Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  51425661_32dd_029c_f8aa_2371b127bd7f["html()"]
  9c9641c6_8e9b_282d_184f_5515feedb7b5["html.js"]
  51425661_32dd_029c_f8aa_2371b127bd7f -->|defined in| 9c9641c6_8e9b_282d_184f_5515feedb7b5
  cb33ef2f_2e6e_0042_436d_4ff6a84c5836["template_effect()"]
  51425661_32dd_029c_f8aa_2371b127bd7f -->|calls| cb33ef2f_2e6e_0042_436d_4ff6a84c5836
  b31601aa_35ce_7827_5394_99fb97fa27d2["hydrate_next()"]
  51425661_32dd_029c_f8aa_2371b127bd7f -->|calls| b31601aa_35ce_7827_5394_99fb97fa27d2
  7eefb76e_3c72_e728_fb79_d79d39793729["remove_effect_dom()"]
  51425661_32dd_029c_f8aa_2371b127bd7f -->|calls| 7eefb76e_3c72_e728_fb79_d79d39793729
  4776c976_30bb_448d_921d_ee70a7fa0135["get_next_sibling()"]
  51425661_32dd_029c_f8aa_2371b127bd7f -->|calls| 4776c976_30bb_448d_921d_ee70a7fa0135
  5ec9c9f6_f767_0a42_fdd7_0cedb5a42d33["hydration_mismatch()"]
  51425661_32dd_029c_f8aa_2371b127bd7f -->|calls| 5ec9c9f6_f767_0a42_fdd7_0cedb5a42d33
  561f74af_4827_cde5_aa05_c2b8149b0a0f["check_hash()"]
  51425661_32dd_029c_f8aa_2371b127bd7f -->|calls| 561f74af_4827_cde5_aa05_c2b8149b0a0f
  e23e5c5c_05b1_afa5_e280_5c89012b55a7["assign_nodes()"]
  51425661_32dd_029c_f8aa_2371b127bd7f -->|calls| e23e5c5c_05b1_afa5_e280_5c89012b55a7
  40f27ad3_30bb_8f2a_3fb3_757088cf7428["set_hydrate_node()"]
  51425661_32dd_029c_f8aa_2371b127bd7f -->|calls| 40f27ad3_30bb_8f2a_3fb3_757088cf7428
  0fd60e7d_ad18_dc03_875d_13156cdee4b4["create_fragment_from_html()"]
  51425661_32dd_029c_f8aa_2371b127bd7f -->|calls| 0fd60e7d_ad18_dc03_875d_13156cdee4b4
  f3bd5a62_2879_ccbe_7046_712cbf9eeaab["get_first_child()"]
  51425661_32dd_029c_f8aa_2371b127bd7f -->|calls| f3bd5a62_2879_ccbe_7046_712cbf9eeaab
  style 51425661_32dd_029c_f8aa_2371b127bd7f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/internal/client/dom/blocks/html.js lines 44–121

export function html(node, get_value, svg = false, mathml = false, skip_warning = false) {
	var anchor = node;

	var value = '';

	template_effect(() => {
		var effect = /** @type {Effect} */ (active_effect);

		if (value === (value = get_value() ?? '')) {
			if (hydrating) hydrate_next();
			return;
		}

		if (effect.nodes !== null) {
			remove_effect_dom(effect.nodes.start, /** @type {TemplateNode} */ (effect.nodes.end));
			effect.nodes = null;
		}

		if (value === '') return;

		if (hydrating) {
			// We're deliberately not trying to repair mismatches between server and client,
			// as it's costly and error-prone (and it's an edge case to have a mismatch anyway)
			var hash = /** @type {Comment} */ (hydrate_node).data;

			/** @type {TemplateNode | null} */
			var next = hydrate_next();
			var last = next;

			while (
				next !== null &&
				(next.nodeType !== COMMENT_NODE || /** @type {Comment} */ (next).data !== '')
			) {
				last = next;
				next = get_next_sibling(next);
			}

			if (next === null) {
				w.hydration_mismatch();
				throw HYDRATION_ERROR;
			}

			if (DEV && !skip_warning) {
				check_hash(/** @type {Element} */ (next.parentNode), hash, value);
			}

			assign_nodes(hydrate_node, last);
			anchor = set_hydrate_node(next);
			return;
		}

		var html = value + '';
		if (svg) html = `<svg>${html}</svg>`;
		else if (mathml) html = `<math>${html}</math>`;

		// Don't use create_fragment_with_script_from_html here because that would mean script tags are executed.
		// @html is basically `.innerHTML = ...` and that doesn't execute scripts either due to security reasons.
		/** @type {DocumentFragment | Element} */
		var node = create_fragment_from_html(html);

		if (svg || mathml) {
			node = /** @type {Element} */ (get_first_child(node));
		}

		assign_nodes(
			/** @type {TemplateNode} */ (get_first_child(node)),
			/** @type {TemplateNode} */ (node.lastChild)
		);

		if (svg || mathml) {
			while (get_first_child(node)) {
				anchor.before(/** @type {TemplateNode} */ (get_first_child(node)));
			}
		} else {
			anchor.before(node);
		}
	});
}

Domain

Subdomains

Frequently Asked Questions

What does html() do?
html() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/dom/blocks/html.js.
Where is html() defined?
html() is defined in packages/svelte/src/internal/client/dom/blocks/html.js at line 44.
What does html() call?
html() calls 10 function(s): assign_nodes, check_hash, create_fragment_from_html, get_first_child, get_next_sibling, hydrate_next, hydration_mismatch, remove_effect_dom, and 2 more.

Analyze Your Own Codebase

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

Try Supermodel Free