@@ -22,6 +22,7 @@ import type {
2222  TransitionAbort , 
2323}  from  './ReactFiberTracingMarkerComponent.new' ; 
2424import  type  { OffscreenInstance }  from  './ReactFiberOffscreenComponent' ; 
25+ import  type  { ThenableState }  from  './ReactFiberThenable.new' ; 
2526
2627import  { 
2728  warnAboutDeprecatedLifecycles , 
@@ -265,10 +266,8 @@ import {
265266}  from  './ReactFiberAct.new' ; 
266267import  { processTransitionCallbacks }  from  './ReactFiberTracingMarkerComponent.new' ; 
267268import  { 
268-   resetWakeableStateAfterEachAttempt , 
269-   resetThenableStateOnCompletion , 
270-   suspendedThenableDidResolve , 
271-   isTrackingSuspendedThenable , 
269+   getThenableStateAfterSuspending , 
270+   isThenableStateResolved , 
272271}  from  './ReactFiberThenable.new' ; 
273272import  { schedulePostPaintCallback }  from  './ReactPostPaintCallback' ; 
274273
@@ -315,6 +314,7 @@ let workInProgressRootRenderLanes: Lanes = NoLanes;
315314// immediately instead of unwinding the stack. 
316315let workInProgressIsSuspended : boolean  =  false ; 
317316let workInProgressThrownValue : mixed  =  null ; 
317+ let  workInProgressSuspendedThenableState : ThenableState  |  null  =  null ; 
318318
319319// Whether a ping listener was attached during this render. This is slightly 
320320// different that whether something suspended, because we don't add multiple 
@@ -1686,15 +1686,14 @@ function prepareFreshStack(root: FiberRoot, lanes: Lanes): Fiber {
16861686      ) ; 
16871687      interruptedWork  =  interruptedWork . return ; 
16881688    } 
1689-     resetWakeableStateAfterEachAttempt ( ) ; 
1690-     resetThenableStateOnCompletion ( ) ; 
16911689  } 
16921690  workInProgressRoot  =  root ; 
16931691  const  rootWorkInProgress  =  createWorkInProgress ( root . current ,  null ) ; 
16941692  workInProgress  =  rootWorkInProgress ; 
16951693  workInProgressRootRenderLanes  =  renderLanes  =  lanes ; 
16961694  workInProgressIsSuspended  =  false ; 
16971695  workInProgressThrownValue  =  null ; 
1696+   workInProgressSuspendedThenableState  =  null ; 
16981697  workInProgressRootDidAttachPingListener  =  false ; 
16991698  workInProgressRootExitStatus  =  RootInProgress ; 
17001699  workInProgressRootFatalError  =  null ; 
@@ -1729,6 +1728,7 @@ function handleThrow(root, thrownValue): void {
17291728  // as suspending the execution of the work loop. 
17301729  workInProgressIsSuspended  =  true ; 
17311730  workInProgressThrownValue  =  thrownValue ; 
1731+   workInProgressSuspendedThenableState  =  getThenableStateAfterSuspending ( ) ; 
17321732
17331733  const  erroredWork  =  workInProgress ; 
17341734  if  ( erroredWork  ===  null )  { 
@@ -2014,7 +2014,7 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) {
20142014      break ; 
20152015    }  catch  ( thrownValue )  { 
20162016      handleThrow ( root ,  thrownValue ) ; 
2017-       if  ( isTrackingSuspendedThenable ( ) )  { 
2017+       if  ( workInProgressSuspendedThenableState   !==   null )  { 
20182018        // If this fiber just suspended, it's possible the data is already 
20192019        // cached. Yield to the main thread to give it a chance to ping. If 
20202020        // it does, we can retry immediately without unwinding the stack. 
@@ -2117,13 +2117,14 @@ function resumeSuspendedUnitOfWork(
21172117  // instead of unwinding the stack. It's a separate function to keep the 
21182118  // additional logic out of the work loop's hot path. 
21192119
2120-   const  wasPinged  =  suspendedThenableDidResolve ( ) ; 
2121-   resetWakeableStateAfterEachAttempt ( ) ; 
2120+   const  wasPinged  = 
2121+     workInProgressSuspendedThenableState  !==  null  && 
2122+     isThenableStateResolved ( workInProgressSuspendedThenableState ) ; 
21222123
21232124  if  ( ! wasPinged )  { 
21242125    // The thenable wasn't pinged. Return to the normal work loop. This will 
21252126    // unwind the stack, and potentially result in showing a fallback. 
2126-     resetThenableStateOnCompletion ( ) ; 
2127+     workInProgressSuspendedThenableState   =   null ; 
21272128
21282129    const  returnFiber  =  unitOfWork . return ; 
21292130    if  ( returnFiber  ===  null  ||  workInProgressRoot  ===  null )  { 
@@ -2188,7 +2189,7 @@ function resumeSuspendedUnitOfWork(
21882189  // The begin phase finished successfully without suspending. Reset the state 
21892190  // used to track the fiber while it was suspended. Then return to the normal 
21902191  // work loop. 
2191-   resetThenableStateOnCompletion ( ) ; 
2192+   workInProgressSuspendedThenableState   =   null ; 
21922193
21932194  resetCurrentDebugFiberInDEV ( ) ; 
21942195  unitOfWork . memoizedProps  =  unitOfWork . pendingProps ; 
@@ -2202,6 +2203,10 @@ function resumeSuspendedUnitOfWork(
22022203  ReactCurrentOwner . current  =  null ; 
22032204} 
22042205
2206+ export  function  getSuspendedThenableState ( ) : ThenableState  |  null  { 
2207+   return workInProgressSuspendedThenableState ; 
2208+ } 
2209+ 
22052210function  completeUnitOfWork ( unitOfWork : Fiber ) : void  { 
22062211  // Attempt to complete the current unit of work, then move to the next 
22072212  // sibling. If there are no more siblings, return to the parent fiber. 
0 commit comments