From 85ea9f59c0366891ce4c54f869cf3f250f91f3fa Mon Sep 17 00:00:00 2001 From: Tianer Zhou Date: Mon, 14 Apr 2025 21:16:00 +0800 Subject: [PATCH] fix recompute range of Reusable scope Signed-off-by: Tianer Zhou --- incremental/runtime/src/states/State.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/incremental/runtime/src/states/State.ts b/incremental/runtime/src/states/State.ts index aab34f593c..bf20d8f3ac 100644 --- a/incremental/runtime/src/states/State.ts +++ b/incremental/runtime/src/states/State.ts @@ -222,6 +222,17 @@ interface ManagedScope extends Disposable, Dependency, ReadonlyTreeNode { reuseKey?: string ): ScopeImpl increment(count: uint32, skip: boolean): void + /** + * when reused, need to recompute scopes between Reusable scope and its direct child node + * Reusable Scope + * | + * Scope + * | + * Scope + * / \ + * Scope Node + */ + invalidateOnReuse(): void } class StateImpl implements Observable, ManagedState, MutableState { @@ -877,6 +888,17 @@ class ScopeImpl implements ManagedScope, InternalScope, Computable statesNamed.set(name, state) } + invalidateOnReuse(): void { + this.recomputeNeeded = true + for (let child = this.child; child; child = child?.next) { + if (child?.node) + return + if (child?.once) + continue + child?.invalidateOnReuse() + } + } + getNamedState(name: string): MutableState | undefined { const state = this.statesNamed?.get(name) return state ? state as MutableState : undefined @@ -900,8 +922,8 @@ class ScopeImpl implements ManagedScope, InternalScope, Computable const scope = reused ? reused as ScopeImpl : ScopeImpl.create(id, paramCount, compute, cleanup, reuseKey) scope.manager = manager if (reused) { - scope.recomputeNeeded = true scope._id = id // children scope IDs are independent from Reusable parent + scope.invalidateOnReuse() } else if (create) { // create node within a scope scope._once = true -- Gitee