@@ -75,6 +75,7 @@ import {
7575 MutationMask ,
7676 LayoutMask ,
7777 PassiveMask ,
78+ Visibility ,
7879} from './ReactFiberFlags' ;
7980import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber' ;
8081import invariant from 'shared/invariant' ;
@@ -615,7 +616,7 @@ function commitLayoutEffectOnFiber(
615616 finishedWork : Fiber ,
616617 committedLanes : Lanes ,
617618) : void {
618- if ( ( finishedWork . flags & ( Update | Callback ) ) !== NoFlags ) {
619+ if ( ( finishedWork . flags & LayoutMask ) !== NoFlags ) {
619620 switch ( finishedWork . tag ) {
620621 case FunctionComponent :
621622 case ForwardRef :
@@ -1776,7 +1777,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
17761777 return ;
17771778 }
17781779 case SuspenseComponent : {
1779- commitSuspenseComponent ( finishedWork ) ;
1780+ commitSuspenseCallback ( finishedWork ) ;
17801781 attachSuspenseRetryListeners ( finishedWork ) ;
17811782 return ;
17821783 }
@@ -1899,7 +1900,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
18991900 return ;
19001901 }
19011902 case SuspenseComponent : {
1902- commitSuspenseComponent ( finishedWork ) ;
1903+ commitSuspenseCallback ( finishedWork ) ;
19031904 attachSuspenseRetryListeners ( finishedWork ) ;
19041905 return ;
19051906 }
@@ -1918,13 +1919,6 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
19181919 }
19191920 break ;
19201921 }
1921- case OffscreenComponent :
1922- case LegacyHiddenComponent : {
1923- const newState : OffscreenState | null = finishedWork . memoizedState ;
1924- const isHidden = newState !== null ;
1925- hideOrUnhideAllChildren ( finishedWork , isHidden ) ;
1926- return ;
1927- }
19281922 }
19291923 invariant (
19301924 false ,
@@ -1933,27 +1927,9 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
19331927 ) ;
19341928}
19351929
1936- function commitSuspenseComponent ( finishedWork : Fiber ) {
1930+ function commitSuspenseCallback ( finishedWork : Fiber ) {
1931+ // TODO: Move this to passive phase
19371932 const newState : SuspenseState | null = finishedWork . memoizedState ;
1938-
1939- if ( newState !== null ) {
1940- markCommitTimeOfFallback ( ) ;
1941-
1942- if ( supportsMutation ) {
1943- // Hide the Offscreen component that contains the primary children. TODO:
1944- // Ideally, this effect would have been scheduled on the Offscreen fiber
1945- // itself. That's how unhiding works: the Offscreen component schedules an
1946- // effect on itself. However, in this case, the component didn't complete,
1947- // so the fiber was never added to the effect list in the normal path. We
1948- // could have appended it to the effect list in the Suspense component's
1949- // second pass, but doing it this way is less complicated. This would be
1950- // simpler if we got rid of the effect list and traversed the tree, like
1951- // we're planning to do.
1952- const primaryChildParent : Fiber = ( finishedWork . child : any ) ;
1953- hideOrUnhideAllChildren ( primaryChildParent , true ) ;
1954- }
1955- }
1956-
19571933 if ( enableSuspenseCallback && newState !== null ) {
19581934 const suspenseCallback = finishedWork . memoizedProps . suspenseCallback ;
19591935 if ( typeof suspenseCallback === 'function' ) {
@@ -2127,6 +2103,10 @@ function commitMutationEffects_complete(root: FiberRoot) {
21272103}
21282104
21292105function commitMutationEffectsOnFiber ( finishedWork : Fiber , root : FiberRoot ) {
2106+ // TODO: The factoring of this phase function could probably be improved. Consider
2107+ // switching on the type of work before checking the flags. That's what
2108+ // we do in all the other phases. I think this one is only different
2109+ // because of the shared reconcilation logic below.
21302110 const flags = finishedWork . flags ;
21312111
21322112 if ( flags & ContentReset ) {
@@ -2147,6 +2127,37 @@ function commitMutationEffectsOnFiber(finishedWork: Fiber, root: FiberRoot) {
21472127 }
21482128 }
21492129
2130+ if ( flags & Visibility ) {
2131+ switch ( finishedWork . tag ) {
2132+ case SuspenseComponent : {
2133+ const newState : OffscreenState | null = finishedWork . memoizedState ;
2134+ if ( newState !== null ) {
2135+ markCommitTimeOfFallback ( ) ;
2136+ // Hide the Offscreen component that contains the primary children.
2137+ // TODO: Ideally, this effect would have been scheduled on the
2138+ // Offscreen fiber itself. That's how unhiding works: the Offscreen
2139+ // component schedules an effect on itself. However, in this case, the
2140+ // component didn't complete, so the fiber was never added to the
2141+ // effect list in the normal path. We could have appended it to the
2142+ // effect list in the Suspense component's second pass, but doing it
2143+ // this way is less complicated. This would be simpler if we got rid
2144+ // of the effect list and traversed the tree, like we're planning to
2145+ // do.
2146+ const primaryChildParent : Fiber = ( finishedWork . child : any ) ;
2147+ hideOrUnhideAllChildren ( primaryChildParent , true ) ;
2148+ }
2149+ break ;
2150+ }
2151+ case OffscreenComponent:
2152+ case LegacyHiddenComponent : {
2153+ const newState : OffscreenState | null = finishedWork . memoizedState ;
2154+ const isHidden = newState !== null ;
2155+ hideOrUnhideAllChildren ( finishedWork , isHidden ) ;
2156+ break ;
2157+ }
2158+ }
2159+ }
2160+
21502161 // The following switch statement is only concerned about placement,
21512162 // updates, and deletions. To avoid needing to add a case for every possible
21522163 // bitmap value, we remove the secondary effects from the effect tag and
0 commit comments