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

Function key

packages/svelte/src/internal/client/dom/blocks/key.js:16–40  ·  view source on GitHub ↗
(node, get_key, render_fn)

Source from the content-addressed store, hash-verified

14 * @returns {void}
15 */
16export function key(node, get_key, render_fn) {
17 if (hydrating) {
18 hydrate_next();
19 }
20
21 var branches = new BranchManager(node);
22
23 var legacy = !is_runes();
24
25 block(() => {
26 var key = get_key();
27
28 // NaN !== NaN, hence we do this workaround to not trigger remounts unnecessarily
29 if (key !== key) {
30 key = /** @type {any} */ (NAN);
31 }
32
33 // key blocks in Svelte <5 had stupid semantics
34 if (legacy && key !== null && typeof key === 'object') {
35 key = /** @type {V} */ ({});
36 }
37
38 branches.ensure(key, render_fn);
39 });
40}

Callers

nothing calls this directly

Calls 4

ensureMethod · 0.95
hydrate_nextFunction · 0.90
is_runesFunction · 0.90
blockFunction · 0.90

Tested by

no test coverage detected