@samitouri / QOS-React-1 / commits / 6639ed3b3a

refactor[isChildPublicInstance]: don't leak ReactNativeFiberHostComponent to Fabric implementation (#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.

Ruslan Lesiutin committed Jan 11, 2024 at 14:26 UTC 6639ed3b3a44f7736beb629144a7996145008f09
1 file changed +13 -16
packages/react-native-renderer/src/ReactNativePublicCompat.js
+13 -16
@@ -27,8 +27,6 @@ import {doesFiberContain} from 'react-reconciler/src/ReactFiberTreeReflection';
27 import ReactSharedInternals from 'shared/ReactSharedInternals';
28 import getComponentNameFromType from 'shared/getComponentNameFromType';
29
30 -import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent';
31 -
30 const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
31
32 export function findHostInstance_DEPRECATED<TElementType: ElementType>(
@@ -236,21 +234,19 @@ export function isChildPublicInstance(
234 if (__DEV__) {
235 // Paper
236 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
243 ) {
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 + );
250 }
251
252 const parentInternalInstanceHandle =
@@ -271,6 +267,7 @@ export function isChildPublicInstance(
267 );
268 }
269
270 + // Means that one instance is from Fabric and other is from Paper.
271 return false;
272 } else {
273 throw new Error('isChildPublicInstance() is not available in production.');