Skip to content

Commit

Permalink
refactor[isChildPublicInstance]: don't leak ReactNativeFiberHostCompo…
Browse files Browse the repository at this point in the history
…nent to Fabric implementation
  • Loading branch information
hoxyq committed Jan 11, 2024
1 parent 49439b4 commit 2a4a686
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions packages/react-native-renderer/src/ReactNativePublicCompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import {doesFiberContain} from 'react-reconciler/src/ReactFiberTreeReflection';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import getComponentNameFromType from 'shared/getComponentNameFromType';

import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent';

const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;

export function findHostInstance_DEPRECATED<TElementType: ElementType>(
Expand Down Expand Up @@ -234,25 +232,6 @@ export function isChildPublicInstance(
childInstance: FabricPublicInstance | PaperPublicInstance,
): boolean {
if (__DEV__) {
// Paper
if (
parentInstance instanceof ReactNativeFiberHostComponent ||
childInstance instanceof ReactNativeFiberHostComponent
) {
if (
parentInstance instanceof ReactNativeFiberHostComponent &&
childInstance instanceof ReactNativeFiberHostComponent
) {
return doesFiberContain(
parentInstance._internalFiberInstanceHandleDEV,
childInstance._internalFiberInstanceHandleDEV,
);
}

// Means that one instance is from Fabric and other is from Paper.
return false;
}

const parentInternalInstanceHandle =
// $FlowExpectedError[incompatible-call] Type for parentInstance should have been PublicInstance from ReactFiberConfigFabric.
getInternalInstanceHandleFromPublicInstance(parentInstance);
Expand All @@ -271,6 +250,24 @@ export function isChildPublicInstance(
);
}

// Paper
if (
// $FlowExpectedError[incompatible-type]
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
parentInstance._internalFiberInstanceHandleDEV &&
// $FlowExpectedError[incompatible-type]
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
childInstance._internalFiberInstanceHandleDEV
) {
return doesFiberContain(
// $FlowExpectedError[incompatible-call]
parentInstance._internalFiberInstanceHandleDEV,
// $FlowExpectedError[incompatible-call]
childInstance._internalFiberInstanceHandleDEV,
);
}

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

0 comments on commit 2a4a686

Please sign in to comment.