diff --git a/compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts b/compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts index 01f61a88fe..c5a7970793 100644 --- a/compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts +++ b/compiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts @@ -505,7 +505,7 @@ class Context { currentDeclaration !== undefined && currentDeclaration.id < currentScope.range.start && (currentDeclaration.scope == null || - !this.#isScopeActive(currentDeclaration.scope)) + currentDeclaration.scope !== currentScope) ) { // Check if there is an existing dependency that describes this operand // We do not try to join/reduce dependencies here due to missing info diff --git a/compiler/forget/src/__tests__/fixtures/hir/allocating-primitive-as-dep.expect.md b/compiler/forget/src/__tests__/fixtures/hir/allocating-primitive-as-dep.expect.md index d50063894e..e6031161e4 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/allocating-primitive-as-dep.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/allocating-primitive-as-dep.expect.md @@ -53,7 +53,7 @@ function AllocatingPrimitiveAsDep(props) { } function PrimitiveAsDepNested(props) { - const $ = React.unstable_useMemoCache(8); + const $ = React.unstable_useMemoCache(10); const c_0 = $[0] !== props.b; const c_1 = $[1] !== props.a; let x; @@ -69,12 +69,15 @@ function PrimitiveAsDepNested(props) { } else { t0 = $[4]; } + const t1 = t0 + 1; + const c_5 = $[5] !== t1; let y; - if ($[5] === Symbol.for("react.memo_cache_sentinel")) { - y = foo(t0 + 1); - $[5] = y; + if (c_5) { + y = foo(t1); + $[5] = t1; + $[6] = y; } else { - y = $[5]; + y = $[6]; } mutate(x, props.a); $[0] = props.b; @@ -83,16 +86,18 @@ function PrimitiveAsDepNested(props) { } else { x = $[2]; } - const c_6 = $[6] !== x; - let t1; - if (c_6) { - t1 = [x, y]; - $[6] = x; - $[7] = t1; + const c_7 = $[7] !== x; + const c_8 = $[8] !== y; + let t2; + if (c_7 || c_8) { + t2 = [x, y]; + $[7] = x; + $[8] = y; + $[9] = t2; } else { - t1 = $[7]; + t2 = $[9]; } - return t1; + return t2; } ``` diff --git a/compiler/forget/src/__tests__/fixtures/hir/primitive-as-dep.expect.md b/compiler/forget/src/__tests__/fixtures/hir/primitive-as-dep.expect.md index f06413e71b..d7066d71a9 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/primitive-as-dep.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/primitive-as-dep.expect.md @@ -46,19 +46,22 @@ function PrimitiveAsDep(props) { } function PrimitiveAsDepNested(props) { - const $ = React.unstable_useMemoCache(6); + const $ = React.unstable_useMemoCache(8); const c_0 = $[0] !== props.b; const c_1 = $[1] !== props.a; let x; if (c_0 || c_1) { x = {}; mutate(x); + const t0 = props.b + 1; + const c_3 = $[3] !== t0; let y; - if ($[3] === Symbol.for("react.memo_cache_sentinel")) { - y = foo(props.b + 1); - $[3] = y; + if (c_3) { + y = foo(t0); + $[3] = t0; + $[4] = y; } else { - y = $[3]; + y = $[4]; } mutate(x, props.a); $[0] = props.b; @@ -67,16 +70,18 @@ function PrimitiveAsDepNested(props) { } else { x = $[2]; } - const c_4 = $[4] !== x; - let t0; - if (c_4) { - t0 = [x, y]; - $[4] = x; - $[5] = t0; + const c_5 = $[5] !== x; + const c_6 = $[6] !== y; + let t1; + if (c_5 || c_6) { + t1 = [x, y]; + $[5] = x; + $[6] = y; + $[7] = t1; } else { - t0 = $[5]; + t1 = $[7]; } - return t0; + return t1; } ```