File tree Expand file tree Collapse file tree
packages/react-reconciler/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2389,11 +2389,11 @@ function startTransition(
23892389 higherEventPriority ( previousPriority , ContinuousEventPriority ) ,
23902390 ) ;
23912391
2392- setPending ( true ) ;
2393-
23942392 const prevTransition = ReactCurrentBatchConfig . transition ;
2395- ReactCurrentBatchConfig . transition = ( { } : BatchConfigTransition ) ;
2396- const currentTransition = ReactCurrentBatchConfig . transition ;
2393+ ReactCurrentBatchConfig . transition = null ;
2394+ setPending ( true ) ;
2395+ const currentTransition = ( ReactCurrentBatchConfig . transition =
2396+ ( { } : BatchConfigTransition ) ) ;
23972397
23982398 if ( enableTransitionTracing ) {
23992399 if ( options !== undefined && options . name !== undefined ) {
Original file line number Diff line number Diff line change @@ -951,4 +951,50 @@ describe('ReactTransition', () => {
951951
952952 expect ( root ) . toMatchRenderedOutput ( 'Transition pri: 1, Normal pri: 1' ) ;
953953 } ) ;
954+
955+ it ( 'tracks two pending flags for nested startTransition (#26226)' , async ( ) => {
956+ let update ;
957+ function App ( ) {
958+ const [ isPendingA , startTransitionA ] = useTransition ( ) ;
959+ const [ isPendingB , startTransitionB ] = useTransition ( ) ;
960+ const [ state , setState ] = useState ( 0 ) ;
961+
962+ update = function ( ) {
963+ startTransitionA ( ( ) => {
964+ startTransitionB ( ( ) => {
965+ setState ( 1 ) ;
966+ } ) ;
967+ } ) ;
968+ } ;
969+
970+ return (
971+ < >
972+ < Text text = { state } />
973+ { ', ' }
974+ < Text text = { 'A ' + isPendingA } />
975+ { ', ' }
976+ < Text text = { 'B ' + isPendingB } />
977+ </ >
978+ ) ;
979+ }
980+ const root = ReactNoop . createRoot ( ) ;
981+ await act ( async ( ) => {
982+ root . render ( < App /> ) ;
983+ } ) ;
984+ expect ( Scheduler ) . toHaveYielded ( [ 0 , 'A false' , 'B false' ] ) ;
985+ expect ( root ) . toMatchRenderedOutput ( '0, A false, B false' ) ;
986+
987+ await act ( async ( ) => {
988+ update ( ) ;
989+ } ) ;
990+ expect ( Scheduler ) . toHaveYielded ( [
991+ 0 ,
992+ 'A true' ,
993+ 'B true' ,
994+ 1 ,
995+ 'A false' ,
996+ 'B false' ,
997+ ] ) ;
998+ expect ( root ) . toMatchRenderedOutput ( '1, A false, B false' ) ;
999+ } ) ;
9541000} ) ;
You can’t perform that action at this time.
0 commit comments