From 6d6cbe0b2f8778db44087cf0e091b7c76e275ae6 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Thu, 15 Oct 2026 15:42:00 -0500 Subject: [PATCH] perf(react-compiler): enable useSafeTimeout Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e632d4e3-54d2-4423-9888-8e37b00494a3 --- .changeset/react-compiler-safe-timeout.md | 5 +++++ packages/react/script/react-compiler.mjs | 1 - packages/react/src/hooks/useSafeTimeout.ts | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 .changeset/react-compiler-safe-timeout.md diff --git a/.changeset/react-compiler-safe-timeout.md b/.changeset/react-compiler-safe-timeout.md new file mode 100644 index 00000000000..f03fcec132b --- /dev/null +++ b/.changeset/react-compiler-safe-timeout.md @@ -0,0 +1,5 @@ +--- +'@primer/react': minor +--- + +useSafeTimeout: Support automatic memoization with React Compiler. diff --git a/packages/react/script/react-compiler.mjs b/packages/react/script/react-compiler.mjs index dab247978a0..1999567b8a1 100644 --- a/packages/react/script/react-compiler.mjs +++ b/packages/react/script/react-compiler.mjs @@ -39,7 +39,6 @@ const unsupportedPatterns = [ 'src/hooks/useOnEscapePress.ts', 'src/hooks/useOnOutsideClick.tsx', 'src/hooks/useResizeObserver.ts', - 'src/hooks/useSafeTimeout.ts', 'src/internal/hooks/__tests__/useFocus.test.tsx', 'src/internal/hooks/useDevOnlyEffect.ts', 'src/utils/StressTest.tsx', diff --git a/packages/react/src/hooks/useSafeTimeout.ts b/packages/react/src/hooks/useSafeTimeout.ts index 2ee793c24d8..96922e6c813 100644 --- a/packages/react/src/hooks/useSafeTimeout.ts +++ b/packages/react/src/hooks/useSafeTimeout.ts @@ -26,9 +26,9 @@ export default function useSafeTimeout(): {safeSetTimeout: SetTimeout; safeClear }, []) useEffect(() => { + const timerSet = timers.current return () => { - // eslint-disable-next-line react-hooks/exhaustive-deps - for (const id of timers.current) { + for (const id of timerSet) { clearTimeout(id) } }