@@ -75,6 +75,7 @@ import {
75
75
MutationMask ,
76
76
LayoutMask ,
77
77
PassiveMask ,
78
+ Visibility ,
78
79
} from './ReactFiberFlags' ;
79
80
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber' ;
80
81
import invariant from 'shared/invariant' ;
@@ -615,7 +616,7 @@ function commitLayoutEffectOnFiber(
615
616
finishedWork : Fiber ,
616
617
committedLanes : Lanes ,
617
618
) : void {
618
- if ( ( finishedWork . flags & ( Update | Callback ) ) !== NoFlags ) {
619
+ if ( ( finishedWork . flags & LayoutMask ) !== NoFlags ) {
619
620
switch ( finishedWork . tag ) {
620
621
case FunctionComponent :
621
622
case ForwardRef :
@@ -1776,7 +1777,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
1776
1777
return ;
1777
1778
}
1778
1779
case SuspenseComponent : {
1779
- commitSuspenseComponent ( finishedWork ) ;
1780
+ commitSuspenseCallback ( finishedWork ) ;
1780
1781
attachSuspenseRetryListeners ( finishedWork ) ;
1781
1782
return ;
1782
1783
}
@@ -1899,7 +1900,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
1899
1900
return ;
1900
1901
}
1901
1902
case SuspenseComponent : {
1902
- commitSuspenseComponent ( finishedWork ) ;
1903
+ commitSuspenseCallback ( finishedWork ) ;
1903
1904
attachSuspenseRetryListeners ( finishedWork ) ;
1904
1905
return ;
1905
1906
}
@@ -1918,13 +1919,6 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
1918
1919
}
1919
1920
break ;
1920
1921
}
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
- }
1928
1922
}
1929
1923
invariant (
1930
1924
false ,
@@ -1933,27 +1927,9 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
1933
1927
) ;
1934
1928
}
1935
1929
1936
- function commitSuspenseComponent ( finishedWork : Fiber ) {
1930
+ function commitSuspenseCallback ( finishedWork : Fiber ) {
1931
+ // TODO: Move this to passive phase
1937
1932
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
-
1957
1933
if ( enableSuspenseCallback && newState !== null ) {
1958
1934
const suspenseCallback = finishedWork . memoizedProps . suspenseCallback ;
1959
1935
if ( typeof suspenseCallback === 'function' ) {
@@ -2127,6 +2103,10 @@ function commitMutationEffects_complete(root: FiberRoot) {
2127
2103
}
2128
2104
2129
2105
function 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.
2130
2110
const flags = finishedWork . flags ;
2131
2111
2132
2112
if ( flags & ContentReset ) {
@@ -2147,6 +2127,37 @@ function commitMutationEffectsOnFiber(finishedWork: Fiber, root: FiberRoot) {
2147
2127
}
2148
2128
}
2149
2129
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
+
2150
2161
// The following switch statement is only concerned about placement,
2151
2162
// updates, and deletions. To avoid needing to add a case for every possible
2152
2163
// bitmap value, we remove the secondary effects from the effect tag and
0 commit comments