diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts index 1e807d6d2a5d0..84671712e9305 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts @@ -1616,7 +1616,12 @@ export function isDispatcherType(id: Identifier): boolean { } export function isStableType(id: Identifier): boolean { - return isSetStateType(id) || isSetActionStateType(id) || isDispatcherType(id); + return ( + isSetStateType(id) || + isSetActionStateType(id) || + isDispatcherType(id) || + isUseRefType(id) + ); } export function isUseEffectHookType(id: Identifier): boolean { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-in-callback-passed-to-jsx-indirect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-in-callback-passed-to-jsx-indirect.expect.md index 7e6dcaff76d10..70320c376274a 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-in-callback-passed-to-jsx-indirect.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-in-callback-passed-to-jsx-indirect.expect.md @@ -40,62 +40,37 @@ import { c as _c } from "react/compiler-runtime"; // @validateRefAccessDuringRen import { useRef } from "react"; function Component() { - const $ = _c(10); + const $ = _c(2); const ref = useRef(null); let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - t0 = () => { + const setRef = () => { if (ref.current !== null) { ref.current = ""; } }; + + t0 = () => { + setRef(); + }; $[0] = t0; } else { t0 = $[0]; } - const setRef = t0; + const onClick = t0; let t1; - if ($[1] !== setRef) { - t1 = () => { - setRef(); - }; - $[1] = setRef; - $[2] = t1; - } else { - t1 = $[2]; - } - const onClick = t1; - let t2; - if ($[3] !== ref) { - t2 = ; - $[3] = ref; - $[4] = t2; - } else { - t2 = $[4]; - } - let t3; - if ($[5] !== onClick) { - t3 =