Skip to content

Commit b1530e7

Browse files
committed
use ref for prop capture to keep React Compiler compliance
1 parent eac4762 commit b1530e7

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/components/NavigationDeferredMount.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {startTransition, useEffect, useState} from 'react';
1+
import {startTransition, useEffect, useRef, useState} from 'react';
22
import type {ReactNode} from 'react';
33
import TransitionTracker from '@libs/Navigation/TransitionTracker';
44

@@ -33,15 +33,15 @@ type NavigationDeferredMountProps = {
3333
*/
3434
function NavigationDeferredMount({placeholder = null, children, waitForUpcomingTransition = true}: NavigationDeferredMountProps): ReactNode {
3535
const [isReady, setIsReady] = useState(false);
36+
// One-shot mount-time config — flipping the prop after mount shouldn't retrigger the wait.
37+
const waitForUpcomingTransitionRef = useRef(waitForUpcomingTransition);
3638

3739
useEffect(() => {
3840
const handle = TransitionTracker.runAfterTransitions({
39-
waitForUpcomingTransition,
41+
waitForUpcomingTransition: waitForUpcomingTransitionRef.current,
4042
callback: () => startTransition(() => setIsReady(true)),
4143
});
4244
return () => handle.cancel();
43-
// `waitForUpcomingTransition` is a one-shot mount-time config — flipping it post-mount shouldn't retrigger the wait.
44-
// eslint-disable-next-line react-hooks/exhaustive-deps
4545
}, []);
4646

4747
return isReady ? children : placeholder;

0 commit comments

Comments
 (0)