Skip to content

Commit 96beacb

Browse files
committed
[RN] Set up test to create public instances lazily in Fabric
1 parent 192555b commit 96beacb

File tree

4 files changed

+53
-19
lines changed

4 files changed

+53
-19
lines changed

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

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ import {
5757
getInspectorDataForInstance,
5858
} from './ReactNativeFiberInspector';
5959

60-
import {passChildrenWhenCloningPersistedNodes} from 'shared/ReactFeatureFlags';
60+
import {
61+
passChildrenWhenCloningPersistedNodes,
62+
enableLazyPublicInstanceInFabric,
63+
} from 'shared/ReactFeatureFlags';
6164
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
6265
import type {ReactContext} from 'shared/ReactTypes';
6366

@@ -93,8 +96,10 @@ export type Instance = {
9396
currentProps: Props,
9497
// Reference to the React handle (the fiber)
9598
internalInstanceHandle: InternalInstanceHandle,
96-
// Exposed through refs.
97-
publicInstance: PublicInstance,
99+
// Exposed through refs. Potentially lazily created.
100+
publicInstance: ?PublicInstance,
101+
// This is only necessary to lazily create `publicInstance`.
102+
publicRootInstance: ?PublicRootInstance,
98103
},
99104
};
100105
export type TextInstance = {
@@ -186,23 +191,37 @@ export function createInstance(
186191
internalInstanceHandle, // internalInstanceHandle
187192
);
188193

189-
const component = createPublicInstance(
190-
tag,
191-
viewConfig,
192-
internalInstanceHandle,
193-
rootContainerInstance.publicInstance,
194-
);
195-
196-
return {
197-
node: node,
198-
canonical: {
199-
nativeTag: tag,
194+
if (enableLazyPublicInstanceInFabric) {
195+
return {
196+
node: node,
197+
canonical: {
198+
nativeTag: tag,
199+
viewConfig,
200+
currentProps: props,
201+
internalInstanceHandle,
202+
publicInstance: null,
203+
publicRootInstance: rootContainerInstance.publicInstance,
204+
},
205+
};
206+
} else {
207+
const component = createPublicInstance(
208+
tag,
200209
viewConfig,
201-
currentProps: props,
202210
internalInstanceHandle,
203-
publicInstance: component,
204-
},
205-
};
211+
rootContainerInstance.publicInstance,
212+
);
213+
214+
return {
215+
node: node,
216+
canonical: {
217+
nativeTag: tag,
218+
viewConfig,
219+
currentProps: props,
220+
internalInstanceHandle,
221+
publicInstance: component,
222+
},
223+
};
224+
}
206225
}
207226

208227
export function createTextInstance(
@@ -277,7 +296,18 @@ export function getChildHostContext(
277296
}
278297

279298
export function getPublicInstance(instance: Instance): null | PublicInstance {
280-
if (instance.canonical != null && instance.canonical.publicInstance != null) {
299+
if (instance.canonical != null) {
300+
if (instance.canonical.publicInstance == null) {
301+
instance.canonical.publicInstance = createPublicInstance(
302+
instance.canonical.nativeTag,
303+
instance.canonical.viewConfig,
304+
instance.canonical.internalInstanceHandle,
305+
instance.canonical.publicRootInstance,
306+
);
307+
// This was only necessary to create the public instance.
308+
instance.canonical.publicRootInstance = null;
309+
}
310+
281311
return instance.canonical.publicInstance;
282312
}
283313

packages/shared/ReactFeatureFlags.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ export const enableUseEffectCRUDOverload = false;
154154

155155
export const enableFastAddPropertiesInDiffing = true;
156156

157+
export const enableLazyPublicInstanceInFabric = false;
158+
157159
// -----------------------------------------------------------------------------
158160
// Ready for next major.
159161
//

packages/shared/forks/ReactFeatureFlags.native-fb-dynamic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ export const enableUseEffectCRUDOverload = __VARIANT__;
2828
export const enableOwnerStacks = __VARIANT__;
2929
export const enableRemoveConsolePatches = __VARIANT__;
3030
export const enableFastAddPropertiesInDiffing = __VARIANT__;
31+
export const enableLazyPublicInstanceInFabric = __VARIANT__;

packages/shared/forks/ReactFeatureFlags.native-fb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const {
3030
enableOwnerStacks,
3131
enableRemoveConsolePatches,
3232
enableFastAddPropertiesInDiffing,
33+
enableLazyPublicInstanceInFabric,
3334
} = dynamicFlags;
3435

3536
// The rest of the flags are static for better dead code elimination.

0 commit comments

Comments
 (0)