Repository: facebook/react
Pull request: fix: add isChildPublicInstance to ReactNativeTypes

Follow-up on https://github.com/facebook/react/pull/27783.

React Native is actually using `ReactNativeTypes`, which are synced from this repo. In order to make `isChildPublicInstance` visible for renderers inside React Native repository, we need to list it in `ReactNativeTypes`.

Because of current circular dependency between React Native and React, it is impossible to actually type it properly:
- Can't import any types in `ReactNativeTypes` from local files, because it will break React Native, once synced.
- Implementations can't use real types in their definitions, because it will break these checks:

https://github.com/facebook/react/blob/223db40d5a04dc3311f963f5296675f7f43139e8/packages/react-native-renderer/fabric.js#L12-L13

https://github.com/facebook/react/blob/223db40d5a04dc3311f963f5296675f7f43139e8/packages/react-native-renderer/index.js#L12-L14

Changed files:
filename: packages/react-native-renderer/src/ReactNativePublicCompat.js
patch: @@ -8,8 +8,6 @@
  */
 
 import type {Node, HostComponent} from './ReactNativeTypes';
-import type {PublicInstance as FabricPublicInstance} from './ReactFiberConfigFabric';
-import type {PublicInstance as PaperPublicInstance} from './ReactFiberConfigNative';
 import type {ElementRef, ElementType} from 'react';
 
 // Modules provided by RN:
@@ -225,6 +223,11 @@ export function getNodeFromInternalInstanceHandle(
   );
 }
 
+// Should have been PublicInstance from ReactFiberConfigFabric
+type FabricPublicInstance = mixed;
+// Should have been PublicInstance from ReactFiberConfigNative
+type PaperPublicInstance = HostComponent<mixed>;
+
 // Remove this once Paper is no longer supported and DOM Node API are enabled by default in RN.
 export function isChildPublicInstance(
   parentInstance: FabricPublicInstance | PaperPublicInstance,
@@ -251,8 +254,10 @@ export function isChildPublicInstance(
     }
 
     const parentInternalInstanceHandle =
+      // $FlowExpectedError[incompatible-call] Type for parentInstance should have been PublicInstance from ReactFiberConfigFabric.
       getInternalInstanceHandleFromPublicInstance(parentInstance);
     const childInternalInstanceHandle =
+      // $FlowExpectedError[incompatible-call] Type for childInstance should have been PublicInstance from ReactFiberConfigFabric.
       getInternalInstanceHandleFromPublicInstance(childInstance);
 
     // Fabric

filename: packages/react-native-renderer/src/ReactNativeTypes.js
patch: @@ -191,6 +191,10 @@ export type ReactNativeType = {
   findNodeHandle<TElementType: ElementType>(
     componentOrHandle: ?(ElementRef<TElementType> | number),
   ): ?number,
+  isChildPublicInstance(
+    parent: PublicInstance | HostComponent<mixed>,
+    child: PublicInstance | HostComponent<mixed>,
+  ): boolean,
   dispatchCommand(
     handle: ElementRef<HostComponent<mixed>>,
     command: string,
@@ -229,6 +233,7 @@ export type ReactFabricType = {
     command: string,
     args: Array<mixed>,
   ): void,
+  isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean,
   sendAccessibilityEvent(
     handle: ElementRef<HostComponent<mixed>>,
     eventType: string,