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

Function update_branch

packages/svelte/src/internal/client/dom/blocks/if.js:36–58  ·  view source on GitHub ↗

* @param {number | false} key * @param {null | ((anchor: Node) => void)} fn

(key, fn)

Source from the content-addressed store, hash-verified

34 * @param {null | ((anchor: Node) => void)} fn
35 */
36 function update_branch(key, fn) {
37 if (hydrating) {
38 var data = read_hydration_instruction(/** @type {TemplateNode} */ (marker));
39
40 // "[n" = branch n, "[-1" = else
41 if (key !== parseInt(data.substring(1))) {
42 // Hydration mismatch: remove everything inside the anchor and start fresh.
43 // This could happen with `{#if browser}...{/if}`, for example
44 var anchor = skip_nodes();
45
46 set_hydrate_node(anchor);
47 branches.anchor = anchor;
48
49 set_hydrating(false);
50 branches.ensure(key, fn);
51 set_hydrating(true);
52
53 return;
54 }
55 }
56
57 branches.ensure(key, fn);
58 }
59
60 block(() => {
61 var has_branch = false;

Callers 1

if_blockFunction · 0.85

Calls 5

skip_nodesFunction · 0.90
set_hydrate_nodeFunction · 0.90
set_hydratingFunction · 0.90
ensureMethod · 0.45

Tested by

no test coverage detected