From b96a3c43f50711062505c848ba6307c977b048e2 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 19 Jan 2026 13:43:37 -0500 Subject: [PATCH] extract new_deps changes to a separate PR --- .../svelte/src/internal/client/runtime.js | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 9fe0e9a0df..0e12324d72 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -110,7 +110,7 @@ export function push_reaction_value(value) { * The dependencies of the reaction that is currently being executed. In many cases, * the dependencies are unchanged between runs, and so this will be `null` unless * and until a new dependency is accessed — we track this via `skipped_deps` - * @type {null | Set} + * @type {null | Value[]} */ let new_deps = null; @@ -236,7 +236,7 @@ export function update_reaction(reaction) { var flags = reaction.f; - new_deps = /** @type {null | Set} */ (null); + new_deps = /** @type {null | Value[]} */ (null); skipped_deps = 0; untracked_writes = null; active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null; @@ -266,13 +266,12 @@ export function update_reaction(reaction) { remove_reactions(reaction, skipped_deps); if (deps !== null && skipped_deps > 0) { - deps.length = skipped_deps + new_deps.size; - i = skipped_deps; - for (var dep of new_deps) { - deps[i++] = dep; + deps.length = skipped_deps + new_deps.length; + for (i = 0; i < new_deps.length; i++) { + deps[skipped_deps + i] = new_deps[i]; } } else { - reaction.deps = deps = Array.from(new_deps); + reaction.deps = deps = new_deps; } if (effect_tracking() && (reaction.f & CONNECTED) !== 0) { @@ -369,7 +368,7 @@ function remove_reaction(signal, dependency) { // Destroying a child effect while updating a parent effect can cause a dependency to appear // to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps` // allows us to skip the expensive work of disconnecting and immediately reconnecting it - (new_deps === null || !new_deps.has(dependency)) + (new_deps === null || !new_deps.includes(dependency)) ) { var derived = /** @type {Derived} */ (dependency); @@ -525,8 +524,10 @@ export function get(signal) { // rather than updating `new_deps`, which creates GC cost if (new_deps === null && deps !== null && deps[skipped_deps] === signal) { skipped_deps++; - } else { - (new_deps ??= new Set()).add(signal); + } else if (new_deps === null) { + new_deps = [signal]; + } else if (!new_deps.includes(signal)) { + new_deps.push(signal); } } } else {