MCPcopy
hub / github.com/sveltejs/svelte / first_child

Function first_child

packages/svelte/src/internal/client/dom/operations.js:141–166  ·  view source on GitHub ↗
(node, is_text = false)

Source from the content-addressed store, hash-verified

139 * @returns {TemplateNode | null}
140 */
141export function first_child(node, is_text = false) {
142 if (!hydrating) {
143 var first = get_first_child(node);
144
145 // TODO prevent user comments with the empty string when preserveComments is true
146 if (first instanceof Comment && first.data === '') return get_next_sibling(first);
147
148 return first;
149 }
150
151 if (is_text) {
152 // if an {expression} is empty during SSR, there might be no
153 // text node to hydrate — we must therefore create one
154 if (hydrate_node?.nodeType !== TEXT_NODE) {
155 var text = create_text();
156
157 hydrate_node?.before(text);
158 set_hydrate_node(text);
159 return text;
160 }
161
162 merge_text_nodes(/** @type {Text} */ (hydrate_node));
163 }
164
165 return hydrate_node;
166}
167
168/**
169 * Don't mark this as side-effect-free, hydration needs to walk all nodes

Callers

nothing calls this directly

Calls 5

set_hydrate_nodeFunction · 0.90
get_first_childFunction · 0.85
get_next_siblingFunction · 0.85
create_textFunction · 0.85
merge_text_nodesFunction · 0.85

Tested by

no test coverage detected