From f752865ca219c34265f1c51cdef210473ada6159 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 17 Jun 2024 22:15:31 -0400 Subject: [PATCH] var --- packages/svelte/src/internal/client/runtime.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 8d9561784..d9468a315 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -402,11 +402,13 @@ export function execute_reaction_fn(reaction) { * @returns {void} */ function remove_reaction(signal, dependency) { - const reactions = dependency.reactions; - let reactions_length = 0; + var reactions = dependency.reactions; + var reactions_length = 0; + if (reactions !== null) { reactions_length = reactions.length - 1; - const index = reactions.indexOf(signal); + var index = reactions.indexOf(signal); + if (index !== -1) { if (reactions_length === 0) { dependency.reactions = null; @@ -417,6 +419,7 @@ function remove_reaction(signal, dependency) { } } } + // If the derived has no reactions, then we can disconnect it from the graph, // allowing it to either reconnect in the future, or be GC'd by the VM. if (reactions_length === 0 && (dependency.f & DERIVED) !== 0) {