@@ -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
@@ -2312,22 +2316,79 @@ function replaySuspendedUnitOfWork(
23122316 // This is a fork of performUnitOfWork specifcally for replaying a fiber that
23132317 // just suspended.
23142318 //
2315- // Instead of unwinding the stack and potentially showing a fallback, unwind
2316- // only the last stack frame, reset the fiber, and try rendering it again.
23172319 const current = unitOfWork . alternate ;
2318- resetSuspendedWorkLoopOnUnwind ( ) ;
2319- unwindInterruptedWork ( current , unitOfWork , workInProgressRootRenderLanes ) ;
2320- unitOfWork = workInProgress = resetWorkInProgress ( unitOfWork , renderLanes ) ;
2321-
23222320 setCurrentDebugFiberInDEV ( unitOfWork ) ;
23232321
23242322 let next ;
2325- if ( enableProfilerTimer && ( unitOfWork . mode & ProfileMode ) !== NoMode ) {
2323+ setCurrentDebugFiberInDEV ( unitOfWork ) ;
2324+ const isProfilingMode =
2325+ enableProfilerTimer && ( unitOfWork . mode & ProfileMode ) !== NoMode ;
2326+ if ( isProfilingMode ) {
23262327 startProfilerTimer ( unitOfWork ) ;
2327- next = beginWork ( current , unitOfWork , renderLanes ) ;
2328+ }
2329+ switch ( unitOfWork . tag ) {
2330+ case IndeterminateComponent: {
2331+ // Because it suspended with `use`, we can assume it's a
2332+ // function component.
2333+ unitOfWork . tag = FunctionComponent ;
2334+ // Fallthrough to the next branch.
2335+ }
2336+ // eslint-disable-next-line no-fallthrough
2337+ case FunctionComponent:
2338+ case ForwardRef: {
2339+ // Resolve `defaultProps`. This logic is copied from `beginWork`.
2340+ // TODO: Consider moving this switch statement into that module. Also,
2341+ // could maybe use this as an opportunity to say `use` doesn't work with
2342+ // `defaultProps` :)
2343+ const Component = unitOfWork . type ;
2344+ const unresolvedProps = unitOfWork . pendingProps ;
2345+ const resolvedProps =
2346+ unitOfWork . elementType === Component
2347+ ? unresolvedProps
2348+ : resolveDefaultProps ( Component , unresolvedProps ) ;
2349+ next = replayFunctionComponent (
2350+ current ,
2351+ unitOfWork ,
2352+ resolvedProps ,
2353+ Component ,
2354+ thenableState ,
2355+ workInProgressRootRenderLanes ,
2356+ ) ;
2357+ break ;
2358+ }
2359+ case SimpleMemoComponent : {
2360+ const Component = unitOfWork . type ;
2361+ const nextProps = unitOfWork . pendingProps ;
2362+ next = replayFunctionComponent (
2363+ current ,
2364+ unitOfWork ,
2365+ nextProps ,
2366+ Component ,
2367+ thenableState ,
2368+ workInProgressRootRenderLanes ,
2369+ ) ;
2370+ break ;
2371+ }
2372+ default: {
2373+ if ( __DEV__ ) {
2374+ console . error (
2375+ 'Unexpected type of work: %s, Currently only function ' +
2376+ 'components are replayed after suspending. This is a bug in React.' ,
2377+ unitOfWork . tag ,
2378+ ) ;
2379+ }
2380+ resetSuspendedWorkLoopOnUnwind ( ) ;
2381+ unwindInterruptedWork ( current , unitOfWork , workInProgressRootRenderLanes ) ;
2382+ unitOfWork = workInProgress = resetWorkInProgress (
2383+ unitOfWork ,
2384+ renderLanes ,
2385+ ) ;
2386+ next = beginWork ( current , unitOfWork , renderLanes ) ;
2387+ break ;
2388+ }
2389+ }
2390+ if ( isProfilingMode ) {
23282391 stopProfilerTimerIfRunningAndRecordDelta ( unitOfWork , true) ;
2329- } else {
2330- next = beginWork ( current , unitOfWork , renderLanes ) ;
23312392 }
23322393
23332394 // The begin phase finished successfully without suspending. Reset the state
0 commit comments