Skip to content

Commit 02320ba

Browse files
committed
Re-add old Fabric Offscreen impl behind flag
There's a chance that facebook#21960 will affect layout in a way that we don't expect, so I'm adding back the old implementation so we can toggle the feature with a flag. The flag should read from the ReactNativeFeatureFlags shim so that we can change it at runtime. I'll do that separately.
1 parent 4225133 commit 02320ba

20 files changed

+257
-150
lines changed

packages/react-native-renderer/src/ReactFabricHostConfig.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,32 @@ export function getOffscreenContainerProps(
457457
}
458458
}
459459

460+
export function cloneHiddenInstance(
461+
instance: Instance,
462+
type: string,
463+
props: Props,
464+
internalInstanceHandle: Object,
465+
): Instance {
466+
const viewConfig = instance.canonical.viewConfig;
467+
const node = instance.node;
468+
const updatePayload = create(
469+
{style: {display: 'none'}},
470+
viewConfig.validAttributes,
471+
);
472+
return {
473+
node: cloneNodeWithNewProps(node, updatePayload),
474+
canonical: instance.canonical,
475+
};
476+
}
477+
478+
export function cloneHiddenTextInstance(
479+
instance: Instance,
480+
text: string,
481+
internalInstanceHandle: Object,
482+
): TextInstance {
483+
throw new Error('Not yet implemented.');
484+
}
485+
460486
export function createContainerChildSet(container: Container): ChildSet {
461487
return createChildNodeSet(container);
462488
}

packages/react-noop-renderer/src/createReactNoop.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,54 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
582582
children,
583583
};
584584
},
585+
586+
cloneHiddenInstance(
587+
instance: Instance,
588+
type: string,
589+
props: Props,
590+
internalInstanceHandle: Object,
591+
): Instance {
592+
const clone = cloneInstance(
593+
instance,
594+
null,
595+
type,
596+
props,
597+
props,
598+
internalInstanceHandle,
599+
true,
600+
null,
601+
);
602+
clone.hidden = true;
603+
return clone;
604+
},
605+
606+
cloneHiddenTextInstance(
607+
instance: TextInstance,
608+
text: string,
609+
internalInstanceHandle: Object,
610+
): TextInstance {
611+
const clone = {
612+
text: instance.text,
613+
id: instance.id,
614+
parent: instance.parent,
615+
hidden: true,
616+
context: instance.context,
617+
};
618+
// Hide from unit tests
619+
Object.defineProperty(clone, 'id', {
620+
value: clone.id,
621+
enumerable: false,
622+
});
623+
Object.defineProperty(clone, 'parent', {
624+
value: clone.parent,
625+
enumerable: false,
626+
});
627+
Object.defineProperty(clone, 'context', {
628+
value: clone.context,
629+
enumerable: false,
630+
});
631+
return clone;
632+
},
585633
};
586634

587635
const NoopRenderer = reconciler(hostConfig);

packages/react-reconciler/src/ReactFiberBeginWork.new.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import {
8585
enableCache,
8686
enableLazyContextPropagation,
8787
enableSuspenseLayoutEffectSemantics,
88+
enablePersistentOffscreenHostContainer,
8889
} from 'shared/ReactFeatureFlags';
8990
import invariant from 'shared/invariant';
9091
import isArray from 'shared/isArray';
@@ -734,7 +735,7 @@ function updateOffscreenComponent(
734735
workInProgress.updateQueue = spawnedCachePool;
735736
}
736737

737-
if (supportsPersistence) {
738+
if (enablePersistentOffscreenHostContainer && supportsPersistence) {
738739
// In persistent mode, the offscreen children are wrapped in a host node.
739740
// TODO: Optimize this to use the OffscreenComponent fiber instead of
740741
// an extra HostComponent fiber. Need to make sure this doesn't break Fabric
@@ -750,12 +751,10 @@ function updateOffscreenComponent(
750751
renderLanes,
751752
);
752753
return offscreenContainer;
753-
}
754-
if (supportsMutation) {
754+
} else {
755755
reconcileChildren(current, workInProgress, nextChildren, renderLanes);
756756
return workInProgress.child;
757757
}
758-
return null;
759758
}
760759

761760
function reconcileOffscreenHostContainer(
@@ -2354,7 +2353,7 @@ function updateSuspenseFallbackChildren(
23542353
currentPrimaryChildFragment.treeBaseDuration;
23552354
}
23562355

2357-
if (supportsPersistence) {
2356+
if (enablePersistentOffscreenHostContainer && supportsPersistence) {
23582357
// In persistent mode, the offscreen children are wrapped in a host node.
23592358
// We need to complete it now, because we're going to skip over its normal
23602359
// complete phase and go straight to rendering the fallback.
@@ -2382,7 +2381,7 @@ function updateSuspenseFallbackChildren(
23822381
primaryChildProps,
23832382
);
23842383

2385-
if (supportsPersistence) {
2384+
if (enablePersistentOffscreenHostContainer && supportsPersistence) {
23862385
// In persistent mode, the offscreen children are wrapped in a host node.
23872386
// We need to complete it now, because we're going to skip over its normal
23882387
// complete phase and go straight to rendering the fallback.

packages/react-reconciler/src/ReactFiberBeginWork.old.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import {
8585
enableCache,
8686
enableLazyContextPropagation,
8787
enableSuspenseLayoutEffectSemantics,
88+
enablePersistentOffscreenHostContainer,
8889
} from 'shared/ReactFeatureFlags';
8990
import invariant from 'shared/invariant';
9091
import isArray from 'shared/isArray';
@@ -734,7 +735,7 @@ function updateOffscreenComponent(
734735
workInProgress.updateQueue = spawnedCachePool;
735736
}
736737

737-
if (supportsPersistence) {
738+
if (enablePersistentOffscreenHostContainer && supportsPersistence) {
738739
// In persistent mode, the offscreen children are wrapped in a host node.
739740
// TODO: Optimize this to use the OffscreenComponent fiber instead of
740741
// an extra HostComponent fiber. Need to make sure this doesn't break Fabric
@@ -750,12 +751,10 @@ function updateOffscreenComponent(
750751
renderLanes,
751752
);
752753
return offscreenContainer;
753-
}
754-
if (supportsMutation) {
754+
} else {
755755
reconcileChildren(current, workInProgress, nextChildren, renderLanes);
756756
return workInProgress.child;
757757
}
758-
return null;
759758
}
760759

761760
function reconcileOffscreenHostContainer(
@@ -2354,7 +2353,7 @@ function updateSuspenseFallbackChildren(
23542353
currentPrimaryChildFragment.treeBaseDuration;
23552354
}
23562355

2357-
if (supportsPersistence) {
2356+
if (enablePersistentOffscreenHostContainer && supportsPersistence) {
23582357
// In persistent mode, the offscreen children are wrapped in a host node.
23592358
// We need to complete it now, because we're going to skip over its normal
23602359
// complete phase and go straight to rendering the fallback.
@@ -2382,7 +2381,7 @@ function updateSuspenseFallbackChildren(
23822381
primaryChildProps,
23832382
);
23842383

2385-
if (supportsPersistence) {
2384+
if (enablePersistentOffscreenHostContainer && supportsPersistence) {
23862385
// In persistent mode, the offscreen children are wrapped in a host node.
23872386
// We need to complete it now, because we're going to skip over its normal
23882387
// complete phase and go straight to rendering the fallback.

0 commit comments

Comments
 (0)