Home / Function/ first_child() — svelte Function Reference

first_child() — svelte Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  e2822fa9_ce29_121f_d14e_d030c9037844["first_child()"]
  9a9bbc27_46b6_021c_6d77_f736ed4b40f0["operations.js"]
  e2822fa9_ce29_121f_d14e_d030c9037844 -->|defined in| 9a9bbc27_46b6_021c_6d77_f736ed4b40f0
  f3bd5a62_2879_ccbe_7046_712cbf9eeaab["get_first_child()"]
  e2822fa9_ce29_121f_d14e_d030c9037844 -->|calls| f3bd5a62_2879_ccbe_7046_712cbf9eeaab
  4776c976_30bb_448d_921d_ee70a7fa0135["get_next_sibling()"]
  e2822fa9_ce29_121f_d14e_d030c9037844 -->|calls| 4776c976_30bb_448d_921d_ee70a7fa0135
  ec54e18a_a454_5d8c_9e00_7bc16e4f49c4["create_text()"]
  e2822fa9_ce29_121f_d14e_d030c9037844 -->|calls| ec54e18a_a454_5d8c_9e00_7bc16e4f49c4
  40f27ad3_30bb_8f2a_3fb3_757088cf7428["set_hydrate_node()"]
  e2822fa9_ce29_121f_d14e_d030c9037844 -->|calls| 40f27ad3_30bb_8f2a_3fb3_757088cf7428
  2471b414_d833_0bea_1bc7_b19c0d8a6d6b["merge_text_nodes()"]
  e2822fa9_ce29_121f_d14e_d030c9037844 -->|calls| 2471b414_d833_0bea_1bc7_b19c0d8a6d6b
  style e2822fa9_ce29_121f_d14e_d030c9037844 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/internal/client/dom/operations.js lines 139–164

export function first_child(node, is_text = false) {
	if (!hydrating) {
		var first = get_first_child(node);

		// TODO prevent user comments with the empty string when preserveComments is true
		if (first instanceof Comment && first.data === '') return get_next_sibling(first);

		return first;
	}

	if (is_text) {
		// if an {expression} is empty during SSR, there might be no
		// text node to hydrate — we must therefore create one
		if (hydrate_node?.nodeType !== TEXT_NODE) {
			var text = create_text();

			hydrate_node?.before(text);
			set_hydrate_node(text);
			return text;
		}

		merge_text_nodes(/** @type {Text} */ (hydrate_node));
	}

	return hydrate_node;
}

Domain

Subdomains

Frequently Asked Questions

What does first_child() do?
first_child() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/dom/operations.js.
Where is first_child() defined?
first_child() is defined in packages/svelte/src/internal/client/dom/operations.js at line 139.
What does first_child() call?
first_child() calls 5 function(s): create_text, get_first_child, get_next_sibling, merge_text_nodes, set_hydrate_node.

Analyze Your Own Codebase

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

Try Supermodel Free