Fix effect updating its own source looping in strict mode

This commit is contained in:
Kaan 2026-10-19 17:18:47 +03:00
parent bafdd3b243
commit a74452f46e
2 changed files with 16 additions and 1 deletions

View file

@ -175,7 +175,7 @@ local update_queue = { n = 0 } :: { n: number, [number]: Node<any> }
local function try_evaluate_node<T>(node: Node<T>): (boolean, string?)
if flags.strict then
if table.find(scopes, node) then
error("a scope, that should rerun due to the update of a source, is already active", 0)
return false, "a scope, that should rerun due to the update of a source, is already active"
end
local initial_value = node.cache

View file

@ -3171,6 +3171,21 @@ TEST("strict", wrap_root(function()
CHECK(count == 4)
end
do CASE "effect updating its own source"
local src = source(0)
local count = 0
effect(function()
count += 1
if count > 100 then return end
local v = src()
if v > 0 then src(v + 1) end
end)
CHECK(not pcall(src, 1))
CHECK(count < 100)
end
do CASE "destruction of active scope"
local src = source(false)
local count = 0