From ec3584e7c25efa023ba906ee0a8ee9e5a3be7578 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 3 Aug 2026 15:32:25 -0400 Subject: [PATCH] Fix --- src/graph.luau | 20 +++++++++++++++++--- todo.md | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/graph.luau b/src/graph.luau index f96bf4e..38d2bfc 100644 --- a/src/graph.luau +++ b/src/graph.luau @@ -228,15 +228,29 @@ local function remove_dependency_counts(node) -- to be called when updating a no for i = 1, #node do local child = node[i] if not node.owner then continue end -- we won't be updating this anyway - node_deps_left[child] -= 1 - remove_dependency_counts(child) + local deps_left = node_deps_left[child] + if deps_left > 1 then + node_deps_left[child] = deps_left - 1 + else + node_deps_left[child] = 0 + -- only recurse if we're removing the last dependency *and* if we aren't planning on updating it + if not in_queue[child] then + remove_dependency_counts(child) + end + end end end local function queue_children_for_update(node: SourceNode) for i = 1, #node do local child = node[i] - node_deps_left[child] -= 1 + local deps_left = node_deps_left[child] + if deps_left then + node_deps_left[child] = deps_left - 1 + else + -- This can happen if child adds parent as a new dependency after the initial update + node_deps_left[child] = 0 + end if not in_queue[child] then in_queue[child] = true update_queue_n += 1 diff --git a/todo.md b/todo.md index 499fbb8..2142d7b 100644 --- a/todo.md +++ b/todo.md @@ -1,3 +1,4 @@ # todo - improve error traces +- prevent redundant re-eval of nodes in complex graphs after a node adds a dependency mid-update