Skip to content

refactor[isChildPublicInstance]: don't leak ReactNativeFiberHostComponent to Fabric implementation #27923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 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 @@ -236,21 +234,19 @@ export function isChildPublicInstance(
if (__DEV__) {
// Paper
if (
parentInstance instanceof ReactNativeFiberHostComponent ||
childInstance instanceof ReactNativeFiberHostComponent
// $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
) {
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;
return doesFiberContain(
// $FlowExpectedError[incompatible-call]
parentInstance._internalFiberInstanceHandleDEV,
// $FlowExpectedError[incompatible-call]
childInstance._internalFiberInstanceHandleDEV,
);
}

const parentInternalInstanceHandle =
Expand All @@ -271,6 +267,7 @@ export function isChildPublicInstance(
);
}

// 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