diff --git a/compiler/forget/src/Inference/AnalyseFunctions.ts b/compiler/forget/src/Inference/AnalyseFunctions.ts index ce245a5a20..93dcf1e6c1 100644 --- a/compiler/forget/src/Inference/AnalyseFunctions.ts +++ b/compiler/forget/src/Inference/AnalyseFunctions.ts @@ -85,6 +85,11 @@ function buildMutatedDeps( continue; } + mutatedDeps.push(dep); + } else if ( + dep.identifier.name !== null && + mutatedIds.has(dep.identifier.name) + ) { mutatedDeps.push(dep); } } diff --git a/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.expect.md b/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.expect.md index 5745524c79..37237ef313 100644 --- a/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.expect.md +++ b/compiler/forget/src/__tests__/fixtures/hir/mutate-captured-arg-separately.expect.md @@ -19,18 +19,20 @@ function component(a) { ```javascript function component(a) { const $ = React.useMemoCache(); + const c_0 = $[0] !== a; let y; - if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + if (c_0) { y = function () { m(x); }; - $[0] = y; - } else { - y = $[0]; - } - const x = { a: a }; - m(x); + const x = { a: a }; + m(x); + $[0] = a; + $[1] = y; + } else { + y = $[1]; + } return y; }