@@ -178,7 +178,10 @@ import {
178178 lanesToEventPriority ,
179179} from './ReactEventPriorities.new' ;
180180import { requestCurrentTransition , NoTransition } from './ReactFiberTransition' ;
181- import { beginWork as originalBeginWork } from './ReactFiberBeginWork.new' ;
181+ import {
182+ beginWork as originalBeginWork ,
183+ replayFunctionComponent ,
184+ } from './ReactFiberBeginWork.new' ;
182185import { completeWork } from './ReactFiberCompleteWork.new' ;
183186import { unwindWork , unwindInterruptedWork } from './ReactFiberUnwindWork.new' ;
184187import {
@@ -279,6 +282,7 @@ import {
279282 getSuspenseHandler ,
280283 isBadSuspenseFallback ,
281284} from './ReactFiberSuspenseContext.new' ;
285+ import { resolveDefaultProps } from './ReactFiberLazyComponent.new' ;
282286
283287const ceil = Math . ceil ;
284288
@@ -2308,22 +2312,79 @@ function replaySuspendedUnitOfWork(
23082312 // This is a fork of performUnitOfWork specifcally for replaying a fiber that
23092313 // just suspended.
23102314 //
2311- // Instead of unwinding the stack and potentially showing a fallback, unwind
2312- // only the last stack frame, reset the fiber, and try rendering it again.
23132315 const current = unitOfWork . alternate ;
2314- resetSuspendedWorkLoopOnUnwind ( ) ;
2315- unwindInterruptedWork ( current , unitOfWork , workInProgressRootRenderLanes ) ;
2316- unitOfWork = workInProgress = resetWorkInProgress ( unitOfWork , renderLanes ) ;
2317-
23182316 setCurrentDebugFiberInDEV ( unitOfWork ) ;
23192317
23202318 let next ;
2321- if ( enableProfilerTimer && ( unitOfWork . mode & ProfileMode ) !== NoMode ) {
2319+ setCurrentDebugFiberInDEV ( unitOfWork ) ;
2320+ const isProfilingMode =
2321+ enableProfilerTimer && ( unitOfWork . mode & ProfileMode ) !== NoMode ;
2322+ if ( isProfilingMode ) {
23222323 startProfilerTimer ( unitOfWork ) ;
2323- next = beginWork ( current , unitOfWork , renderLanes ) ;
2324+ }
2325+ switch ( unitOfWork . tag ) {
2326+ case IndeterminateComponent: {
2327+ // Because it suspended with `use`, we can assume it's a
2328+ // function component.
2329+ unitOfWork . tag = FunctionComponent ;
2330+ // Fallthrough to the next branch.
2331+ }
2332+ // eslint-disable-next-line no-fallthrough
2333+ case FunctionComponent:
2334+ case ForwardRef: {
2335+ // Resolve `defaultProps`. This logic is copied from `beginWork`.
2336+ // TODO: Consider moving this switch statement into that module. Also,
2337+ // could maybe use this as an opportunity to say `use` doesn't work with
2338+ // `defaultProps` :)
2339+ const Component = unitOfWork . type ;
2340+ const unresolvedProps = unitOfWork . pendingProps ;
2341+ const resolvedProps =
2342+ unitOfWork . elementType === Component
2343+ ? unresolvedProps
2344+ : resolveDefaultProps ( Component , unresolvedProps ) ;
2345+ next = replayFunctionComponent (
2346+ current ,
2347+ unitOfWork ,
2348+ resolvedProps ,
2349+ Component ,
2350+ thenableState ,
2351+ workInProgressRootRenderLanes ,
2352+ ) ;
2353+ break ;
2354+ }
2355+ case SimpleMemoComponent : {
2356+ const Component = unitOfWork . type ;
2357+ const nextProps = unitOfWork . pendingProps ;
2358+ next = replayFunctionComponent (
2359+ current ,
2360+ unitOfWork ,
2361+ nextProps ,
2362+ Component ,
2363+ thenableState ,
2364+ workInProgressRootRenderLanes ,
2365+ ) ;
2366+ break ;
2367+ }
2368+ default: {
2369+ if ( __DEV__ ) {
2370+ console . error (
2371+ 'Unexpected type of work: %s, Currently only function ' +
2372+ 'components are replayed after suspending. This is a bug in React.' ,
2373+ unitOfWork . tag ,
2374+ ) ;
2375+ }
2376+ resetSuspendedWorkLoopOnUnwind ( ) ;
2377+ unwindInterruptedWork ( current , unitOfWork , workInProgressRootRenderLanes ) ;
2378+ unitOfWork = workInProgress = resetWorkInProgress (
2379+ unitOfWork ,
2380+ renderLanes ,
2381+ ) ;
2382+ next = beginWork ( current , unitOfWork , renderLanes ) ;
2383+ break ;
2384+ }
2385+ }
2386+ if ( isProfilingMode ) {
23242387 stopProfilerTimerIfRunningAndRecordDelta ( unitOfWork , true) ;
2325- } else {
2326- next = beginWork ( current , unitOfWork , renderLanes ) ;
23272388 }
23282389
23292390 // The begin phase finished successfully without suspending. Reset the state
0 commit comments