@@ -278,7 +278,10 @@ import {
278278 createCapturedValueFromError ,
279279 createCapturedValueAtFiber ,
280280} from './ReactCapturedValue' ;
281- import { createInitialOffscreenInstance } from './ReactFiberOffscreenComponent' ;
281+ import {
282+ OffscreenHidden ,
283+ OffscreenVisible ,
284+ } from './ReactFiberOffscreenComponent' ;
282285import {
283286 createClassErrorUpdate ,
284287 initializeClassErrorUpdate ,
@@ -619,17 +622,21 @@ function updateOffscreenComponent(
619622 const prevState : OffscreenState | null =
620623 current !== null ? current . memoizedState : null ;
621624
625+ const nextHidden =
626+ nextProps . mode === 'hidden' ||
627+ ( enableLegacyHidden && nextProps . mode === 'unstable-defer-without-hiding' ) ;
628+
622629 if ( current === null && workInProgress . stateNode === null ) {
623- // We previously reset the work-in-progress.
624- // We need to create a new Offscreen instance.
625- const primaryChildInstance = createInitialOffscreenInstance ( ) ;
630+ const primaryChildInstance = {
631+ _visibility : nextHidden ? OffscreenHidden : OffscreenVisible ,
632+ _pendingMarkers : null ,
633+ _retryCache : null ,
634+ _transitions : null ,
635+ } ;
626636 workInProgress . stateNode = primaryChildInstance ;
627637 }
628638
629- if (
630- nextProps . mode === 'hidden' ||
631- ( enableLegacyHidden && nextProps . mode === 'unstable-defer-without-hiding' )
632- ) {
639+ if ( nextHidden ) {
633640 // Rendering a hidden tree.
634641
635642 const didSuspend = ( workInProgress . flags & DidCapture ) !== NoFlags ;
@@ -2371,6 +2378,13 @@ function updateSuspenseComponent(
23712378 const primaryChildFragment : Fiber = ( workInProgress . child : any ) ;
23722379 primaryChildFragment . memoizedState =
23732380 mountSuspenseOffscreenState ( renderLanes ) ;
2381+ const primaryChildInstance = {
2382+ _visibility : OffscreenHidden ,
2383+ _pendingMarkers : null ,
2384+ _retryCache : null ,
2385+ _transitions : null ,
2386+ } ;
2387+ primaryChildFragment . stateNode = primaryChildInstance ;
23742388 primaryChildFragment . childLanes = getRemainingWorkInPrimaryTree (
23752389 current ,
23762390 didPrimaryChildrenDefer ,
@@ -2806,7 +2820,7 @@ function mountSuspenseFallbackAfterRetryWithoutHydrating(
28062820) {
28072821 const fiberMode = workInProgress . mode ;
28082822 const primaryChildProps : OffscreenProps = {
2809- mode : 'visible ' ,
2823+ mode : 'hidden ' ,
28102824 children : primaryChildren ,
28112825 } ;
28122826 const primaryChildFragment = mountWorkInProgressOffscreenFiber (
@@ -3065,14 +3079,13 @@ function updateDehydratedSuspenseComponent(
30653079
30663080 const nextPrimaryChildren = nextProps . children ;
30673081 const nextFallbackChildren = nextProps . fallback ;
3068- const fallbackChildFragment =
3069- mountSuspenseFallbackAfterRetryWithoutHydrating (
3070- current ,
3071- workInProgress ,
3072- nextPrimaryChildren ,
3073- nextFallbackChildren ,
3074- renderLanes ,
3075- ) ;
3082+ mountSuspenseFallbackAfterRetryWithoutHydrating (
3083+ current ,
3084+ workInProgress ,
3085+ nextPrimaryChildren ,
3086+ nextFallbackChildren ,
3087+ renderLanes ,
3088+ ) ;
30763089 const primaryChildFragment : Fiber = ( workInProgress . child : any ) ;
30773090 primaryChildFragment . memoizedState =
30783091 mountSuspenseOffscreenState ( renderLanes ) ;
@@ -3082,7 +3095,7 @@ function updateDehydratedSuspenseComponent(
30823095 renderLanes ,
30833096 ) ;
30843097 workInProgress . memoizedState = SUSPENDED_MARKER ;
3085- return fallbackChildFragment ;
3098+ return workInProgress . child ;
30863099 }
30873100 }
30883101}
0 commit comments