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) } }