File tree Expand file tree Collapse file tree 2 files changed +8
-0
lines changed
libs/isograph-react-disposable-state/src Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,10 @@ export function useCachedResponsivePrecommitValue<T>(
5151 const lastCommittedParentCache = useRef < ParentCache < T > | null > ( null ) ;
5252
5353 useEffect ( ( ) => {
54+ // react reruns all `useEffect` in HMR since it doesn't know if the
55+ // code inside of useEffect has changed. Since this is a library
56+ // user can't change this code so we are safe to skip this rerun.
57+ // This also prevents `useEffect` from running twice in Strict Mode.
5458 if ( lastCommittedParentCache . current === parentCache ) {
5559 return ;
5660 }
Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ export function useLazyDisposableState<T>(
3232
3333 const lastCommittedParentCache = useRef < ParentCache < T > | null > ( null ) ;
3434 useEffect ( ( ) => {
35+ // react reruns all `useEffect` in HMR since it doesn't know if the
36+ // code inside of useEffect has changed. Since this is a library
37+ // user can't change this code so we are safe to skip this rerun.
38+ // This also prevents `useEffect` from running twice in Strict Mode.
3539 if ( lastCommittedParentCache . current === parentCache ) {
3640 return ;
3741 }
You can’t perform that action at this time.
0 commit comments