diff --git a/packages/react-reconciler/src/ReactFiberHooks.js b/packages/react-reconciler/src/ReactFiberHooks.js index 6741a55e4b42f..d6d077e57328f 100644 --- a/packages/react-reconciler/src/ReactFiberHooks.js +++ b/packages/react-reconciler/src/ReactFiberHooks.js @@ -2389,11 +2389,11 @@ function startTransition( higherEventPriority(previousPriority, ContinuousEventPriority), ); - setPending(true); - const prevTransition = ReactCurrentBatchConfig.transition; - ReactCurrentBatchConfig.transition = ({}: BatchConfigTransition); - const currentTransition = ReactCurrentBatchConfig.transition; + ReactCurrentBatchConfig.transition = null; + setPending(true); + const currentTransition = (ReactCurrentBatchConfig.transition = + ({}: BatchConfigTransition)); if (enableTransitionTracing) { if (options !== undefined && options.name !== undefined) { diff --git a/packages/react-reconciler/src/__tests__/ReactTransition-test.js b/packages/react-reconciler/src/__tests__/ReactTransition-test.js index dd0b9e0d0fedc..2d26fb6eea8b9 100644 --- a/packages/react-reconciler/src/__tests__/ReactTransition-test.js +++ b/packages/react-reconciler/src/__tests__/ReactTransition-test.js @@ -959,4 +959,50 @@ describe('ReactTransition', () => { expect(root).toMatchRenderedOutput('Transition pri: 1, Normal pri: 1'); }); + + it('tracks two pending flags for nested startTransition (#26226)', async () => { + let update; + function App() { + const [isPendingA, startTransitionA] = useTransition(); + const [isPendingB, startTransitionB] = useTransition(); + const [state, setState] = useState(0); + + update = function () { + startTransitionA(() => { + startTransitionB(() => { + setState(1); + }); + }); + }; + + return ( + <> + + {', '} + + {', '} + + + ); + } + const root = ReactNoop.createRoot(); + await act(async () => { + root.render(); + }); + expect(Scheduler).toHaveYielded([0, 'A false', 'B false']); + expect(root).toMatchRenderedOutput('0, A false, B false'); + + await act(async () => { + update(); + }); + expect(Scheduler).toHaveYielded([ + 0, + 'A true', + 'B true', + 1, + 'A false', + 'B false', + ]); + expect(root).toMatchRenderedOutput('1, A false, B false'); + }); });