Skip to content

Commit d007617

Browse files
hoxyqAndyPengc12
authored andcommitted
refactor[isChildPublicInstance]: don't leak ReactNativeFiberHostComponent to Fabric implementation (facebook#27923)
While inspecting the build artifacts for Fabric in https://www.internalfb.com/diff/D51816108, I've noticed it has some leaking implementation details from Paper, such as `ReactNativeFiberHostComponent`. The reason for it is the single implementation of `isChildPublicInstance` in `ReactNativePublicCompat`, in which we were using `instanceof ReactNativeFiberHostComponent`. This new implementation removes the `ReactNativeFiberHostComponent` leak, but decreases the Flow coverage.
1 parent 0ab9724 commit d007617

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import {doesFiberContain} from 'react-reconciler/src/ReactFiberTreeReflection';
2727
import ReactSharedInternals from 'shared/ReactSharedInternals';
2828
import getComponentNameFromType from 'shared/getComponentNameFromType';
2929

30-
import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent';
31-
3230
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
3331

3432
export function findHostInstance_DEPRECATED<TElementType: ElementType>(
@@ -236,21 +234,19 @@ export function isChildPublicInstance(
236234
if (__DEV__) {
237235
// Paper
238236
if (
239-
parentInstance instanceof ReactNativeFiberHostComponent ||
240-
childInstance instanceof ReactNativeFiberHostComponent
237+
// $FlowExpectedError[incompatible-type]
238+
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
239+
parentInstance._internalFiberInstanceHandleDEV &&
240+
// $FlowExpectedError[incompatible-type]
241+
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
242+
childInstance._internalFiberInstanceHandleDEV
241243
) {
242-
if (
243-
parentInstance instanceof ReactNativeFiberHostComponent &&
244-
childInstance instanceof ReactNativeFiberHostComponent
245-
) {
246-
return doesFiberContain(
247-
parentInstance._internalFiberInstanceHandleDEV,
248-
childInstance._internalFiberInstanceHandleDEV,
249-
);
250-
}
251-
252-
// Means that one instance is from Fabric and other is from Paper.
253-
return false;
244+
return doesFiberContain(
245+
// $FlowExpectedError[incompatible-call]
246+
parentInstance._internalFiberInstanceHandleDEV,
247+
// $FlowExpectedError[incompatible-call]
248+
childInstance._internalFiberInstanceHandleDEV,
249+
);
254250
}
255251

256252
const parentInternalInstanceHandle =
@@ -271,6 +267,7 @@ export function isChildPublicInstance(
271267
);
272268
}
273269

270+
// Means that one instance is from Fabric and other is from Paper.
274271
return false;
275272
} else {
276273
throw new Error('isChildPublicInstance() is not available in production.');

0 commit comments

Comments
 (0)