57
getInspectorDataForInstance,
58
} from './ReactNativeFiberInspector';
59
60
-import {passChildrenWhenCloningPersistedNodes} from 'shared/ReactFeatureFlags';
60
+import {
61
+ passChildrenWhenCloningPersistedNodes,
62
+ enableLazyPublicInstanceInFabric,
63
+} from 'shared/ReactFeatureFlags';
64
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
65
import type {ReactContext} from 'shared/ReactTypes';
66
96
currentProps: Props,
97
// Reference to the React handle (the fiber)
98
internalInstanceHandle: InternalInstanceHandle,
96
- // Exposed through refs.
97
- publicInstance: PublicInstance,
99
+ // Exposed through refs. Potentially lazily created.
100
+ publicInstance: PublicInstance | null,
101
+ // This is only necessary to lazily create `publicInstance`.
102
+ // Will be set to `null` after that is created.
103
+ publicRootInstance?: PublicRootInstance | null,
104
},
105
};
106
export type TextInstance = {
192
internalInstanceHandle, // internalInstanceHandle
193
);
194
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,
195
+ if (enableLazyPublicInstanceInFabric) {
196
+ return {
197
+ node: node,
198
+ canonical: {
199
+ nativeTag: tag,
200
+ viewConfig,
201
+ currentProps: props,
202
+ internalInstanceHandle,
203
+ publicInstance: null,
204
+ publicRootInstance: rootContainerInstance.publicInstance,
205
+ },
206
+ };
207
+ } else {
208
+ const component = createPublicInstance(
209
+ tag,
210
viewConfig,
201
- currentProps: props,
211
internalInstanceHandle,
203
- publicInstance: component,
204
- },
205
- };
212
+ rootContainerInstance.publicInstance,
213
+ );
214
+
215
+ return {
216
+ node: node,
217
+ canonical: {
218
+ nativeTag: tag,
219
+ viewConfig,
220
+ currentProps: props,
221
+ internalInstanceHandle,
222
+ publicInstance: component,
223
+ },
224
+ };
225
+ }
226
}
227
228
export function createTextInstance(
297
}
298
299
export function getPublicInstance(instance: Instance): null | PublicInstance {
280
- if (instance.canonical != null && instance.canonical.publicInstance != null) {
300
+ if (instance.canonical != null) {
301
+ if (instance.canonical.publicInstance == null) {
302
+ instance.canonical.publicInstance = createPublicInstance(
303
+ instance.canonical.nativeTag,
304
+ instance.canonical.viewConfig,
305
+ instance.canonical.internalInstanceHandle,
306
+ instance.canonical.publicRootInstance ?? null,
307
+ );
308
+ // This was only necessary to create the public instance.
309
+ instance.canonical.publicRootInstance = null;
310
+ }
311
+
312
return instance.canonical.publicInstance;
313
}
314