@@ -460,10 +460,10 @@ export function getInternalReactConstants(version: string): {
460460 IncompleteFunctionComponent : 28 ,
461461 IndeterminateComponent : 2 , // removed in 19.0.0
462462 LazyComponent : 16 ,
463- LegacyHiddenComponent : 23 ,
463+ LegacyHiddenComponent : 23 , // Does not exist in 18+ OSS but exists in fb builds
464464 MemoComponent : 14 ,
465465 Mode : 8 ,
466- OffscreenComponent : 22 , // Experimental
466+ OffscreenComponent : 22 , // Experimental in 17. Stable in 18+
467467 Profiler : 12 ,
468468 ScopeComponent : 21 , // Experimental
469469 SimpleMemoComponent : 15 ,
@@ -3057,13 +3057,23 @@ export function attach(
30573057 }
30583058 }
30593059
3060+ function isHiddenOffscreen(fiber: Fiber): boolean {
3061+ switch (fiber.tag) {
3062+ case LegacyHiddenComponent:
3063+ // fallthrough since all published implementations currently implement the same state as Offscreen.
3064+ case OffscreenComponent:
3065+ return fiber.memoizedState !== null;
3066+ default:
3067+ return false;
3068+ }
3069+ }
3070+
30603071 function unmountRemainingChildren() {
30613072 if (
30623073 reconcilingParent !== null &&
30633074 (reconcilingParent.kind === FIBER_INSTANCE ||
30643075 reconcilingParent.kind === FILTERED_FIBER_INSTANCE) &&
3065- reconcilingParent.data.tag === OffscreenComponent &&
3066- reconcilingParent.data.memoizedState !== null &&
3076+ isHiddenOffscreen(reconcilingParent.data) &&
30673077 !isInDisconnectedSubtree
30683078 ) {
30693079 // This is a hidden offscreen, we need to execute this in the context of a disconnected subtree.
@@ -3170,8 +3180,7 @@ export function attach(
31703180 if (
31713181 (parent.kind === FIBER_INSTANCE ||
31723182 parent.kind === FILTERED_FIBER_INSTANCE) &&
3173- parent.data.tag === OffscreenComponent &&
3174- parent.data.memoizedState !== null
3183+ isHiddenOffscreen(parent.data)
31753184 ) {
31763185 // We're inside a hidden offscreen Fiber. We're in a disconnected tree.
31773186 return;
@@ -3819,7 +3828,9 @@ export function attach(
38193828 (reconcilingParent !== null &&
38203829 reconcilingParent.kind === VIRTUAL_INSTANCE) ||
38213830 fiber.tag === SuspenseComponent ||
3822- fiber.tag === OffscreenComponent // Use to keep resuspended instances alive inside a SuspenseComponent.
3831+ // Use to keep resuspended instances alive inside a SuspenseComponent.
3832+ fiber.tag === OffscreenComponent ||
3833+ fiber.tag === LegacyHiddenComponent
38233834 ) {
38243835 // If the parent is a Virtual Instance and we filtered this Fiber we include a
38253836 // hidden node. We also include this if it's a Suspense boundary so we can track those
@@ -3939,7 +3950,7 @@ export function attach(
39393950 trackDebugInfoFromHostComponent(nearestInstance, fiber);
39403951 }
39413952
3942- if (fiber.tag === OffscreenComponent && fiber.memoizedState !== null ) {
3953+ if (isHiddenOffscreen( fiber) ) {
39433954 // If an Offscreen component is hidden, mount its children as disconnected.
39443955 const stashedDisconnected = isInDisconnectedSubtree;
39453956 isInDisconnectedSubtree = true;
@@ -4261,7 +4272,7 @@ export function attach(
42614272 while (child !== null) {
42624273 if (child.kind === FILTERED_FIBER_INSTANCE) {
42634274 const fiber = child.data;
4264- if (fiber.tag === OffscreenComponent && fiber.memoizedState !== null ) {
4275+ if (isHiddenOffscreen( fiber) ) {
42654276 // The children of this Offscreen are hidden so they don't get added.
42664277 } else {
42674278 addUnfilteredChildrenIDs(child, nextChildren);
@@ -4888,9 +4899,8 @@ export function attach(
48884899 const nextDidTimeOut =
48894900 isLegacySuspense && nextFiber.memoizedState !== null;
48904901
4891- const isOffscreen = nextFiber.tag === OffscreenComponent;
4892- const prevWasHidden = isOffscreen && prevFiber.memoizedState !== null;
4893- const nextIsHidden = isOffscreen && nextFiber.memoizedState !== null;
4902+ const prevWasHidden = isHiddenOffscreen(prevFiber);
4903+ const nextIsHidden = isHiddenOffscreen(nextFiber);
48944904
48954905 if (isLegacySuspense) {
48964906 if (
@@ -5245,8 +5255,7 @@ export function attach(
52455255 if (
52465256 (child.kind === FIBER_INSTANCE ||
52475257 child.kind === FILTERED_FIBER_INSTANCE) &&
5248- child.data.tag === OffscreenComponent &&
5249- child.data.memoizedState !== null
5258+ isHiddenOffscreen(child.data)
52505259 ) {
52515260 // This instance's children are already disconnected.
52525261 } else {
@@ -5275,8 +5284,7 @@ export function attach(
52755284 if (
52765285 (child.kind === FIBER_INSTANCE ||
52775286 child.kind === FILTERED_FIBER_INSTANCE) &&
5278- child.data.tag === OffscreenComponent &&
5279- child.data.memoizedState !== null
5287+ isHiddenOffscreen(child.data)
52805288 ) {
52815289 // This instance's children should remain disconnected.
52825290 } else {
0 commit comments