Remove ReactFabricPublicInstance and used definition from ReactNativePrivateInterface (#26437)

## Summary

Now that React Native owns the definition for public instances in Fabric
and ReactNativePrivateInterface provides the methods to create instances
and access private fields (see
https://github.com/facebook/react-native/pull/36570), we can remove the
definitions from React.

After this PR, React Native public instances will be opaque types for
React and it will only handle their creation but not their definition.
This will make RN similar to DOM in how public instances are handled.

This is a new version of #26418 which was closed without merging.

## How did you test this change?

* Existing tests.
* Manually synced the changes in this PR to React Native and tested it
end to end in Meta's infra.

DiffTrain build for commit https://github.com/facebook/react/commit/9c54b29b44d24f8f8090da9c7ebf569747a444df.
This commit is contained in:
rubennorte
2023-03-23 18:42:46 +00:00
parent b87cdfdb10
commit 9dca7fd534
13 changed files with 3255 additions and 3548 deletions
@@ -23649,7 +23649,7 @@ function createFiberRoot(
return root;
}
var ReactVersion = "18.3.0-next-f77099b6f-20230322";
var ReactVersion = "18.3.0-next-9c54b29b4-20230322";
// Might add PROFILE later.
@@ -8570,7 +8570,7 @@ var devToolsConfig$jscomp$inline_1029 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-next-f77099b6f-20230322",
version: "18.3.0-next-9c54b29b4-20230322",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1217 = {
@@ -8601,7 +8601,7 @@ var internals$jscomp$inline_1217 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-f77099b6f-20230322"
reconcilerVersion: "18.3.0-next-9c54b29b4-20230322"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1218 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -8995,7 +8995,7 @@ var devToolsConfig$jscomp$inline_1072 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-next-f77099b6f-20230322",
version: "18.3.0-next-9c54b29b4-20230322",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1258 = {
@@ -9026,7 +9026,7 @@ var internals$jscomp$inline_1258 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-f77099b6f-20230322"
reconcilerVersion: "18.3.0-next-9c54b29b4-20230322"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1259 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -27,7 +27,7 @@ if (
}
"use strict";
var ReactVersion = "18.3.0-next-f77099b6f-20230322";
var ReactVersion = "18.3.0-next-9c54b29b4-20230322";
// ATTENTION
// When adding new symbols to this file,
@@ -639,4 +639,4 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-next-f77099b6f-20230322";
exports.version = "18.3.0-next-9c54b29b4-20230322";
@@ -642,7 +642,7 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-next-f77099b6f-20230322";
exports.version = "18.3.0-next-9c54b29b4-20230322";
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
@@ -1 +1 @@
f77099b6f1ccc658eff3467c6b9337e1b77ec854
9c54b29b44d24f8f8090da9c7ebf569747a444df
@@ -27454,7 +27454,7 @@ function createFiberRoot(
return root;
}
var ReactVersion = "18.3.0-next-f77099b6f-20230322";
var ReactVersion = "18.3.0-next-9c54b29b4-20230322";
function createPortal$1(
children,
@@ -28031,6 +28031,7 @@ function findHostInstance_DEPRECATED(componentOrHandle) {
);
} // findHostInstance handles legacy vs. Fabric differences correctly
// $FlowFixMe[incompatible-exact] we need to fix the definition of `HostComponent` to use NativeMethods as an interface, not as a type.
// $FlowFixMe[incompatible-return]
return hostInstance;
}
@@ -28074,7 +28075,10 @@ function findNodeHandle(componentOrHandle) {
return componentOrHandle.canonical.nativeTag;
} // For compatibility with Fabric public instances
var nativeTag = getNativeTagFromPublicInstance(componentOrHandle);
var nativeTag =
ReactNativePrivateInterface.getNativeTagFromPublicInstance(
componentOrHandle
);
if (nativeTag) {
return nativeTag;
@@ -28091,20 +28095,21 @@ function findNodeHandle(componentOrHandle) {
if (hostInstance == null) {
return hostInstance;
} // $FlowFixMe[prop-missing] For compatibility with legacy renderer instances
} // $FlowFixMe[incompatible-type] For compatibility with legacy renderer instances
if (hostInstance._nativeTag != null) {
// $FlowFixMe[incompatible-return]
return hostInstance._nativeTag;
} // $FlowFixMe[incompatible-call] Necessary when running Flow on the legacy renderer
return getNativeTagFromPublicInstance(hostInstance);
return ReactNativePrivateInterface.getNativeTagFromPublicInstance(
hostInstance
);
}
function dispatchCommand(handle, command, args) {
var nativeTag =
handle._nativeTag != null
? handle._nativeTag
: getNativeTagFromPublicInstance(handle);
: ReactNativePrivateInterface.getNativeTagFromPublicInstance(handle);
if (nativeTag == null) {
{
@@ -28117,7 +28122,7 @@ function dispatchCommand(handle, command, args) {
return;
}
var node = getNodeFromPublicInstance(handle);
var node = ReactNativePrivateInterface.getNodeFromPublicInstance(handle);
if (node != null) {
nativeFabricUIManager.dispatchCommand(node, command, args);
@@ -28133,7 +28138,7 @@ function sendAccessibilityEvent(handle, eventType) {
var nativeTag =
handle._nativeTag != null
? handle._nativeTag
: getNativeTagFromPublicInstance(handle);
: ReactNativePrivateInterface.getNativeTagFromPublicInstance(handle);
if (nativeTag == null) {
{
@@ -28146,7 +28151,7 @@ function sendAccessibilityEvent(handle, eventType) {
return;
}
var node = getNodeFromPublicInstance(handle);
var node = ReactNativePrivateInterface.getNodeFromPublicInstance(handle);
if (node != null) {
nativeFabricUIManager.sendAccessibilityEvent(node, eventType);
@@ -28166,26 +28171,6 @@ function getNodeFromInternalInstanceHandle(internalInstanceHandle) {
);
}
/**
* IMPORTANT: This module is used in Paper and Fabric. It needs to be defined
* outside of `ReactFabricPublicInstance` because that module requires
* `nativeFabricUIManager` to be defined in the global scope (which does not
* happen in Paper).
*/
function getNativeTagFromPublicInstance(publicInstance) {
return publicInstance.__nativeTag;
}
function getNodeFromPublicInstance(publicInstance) {
if (publicInstance.__internalInstanceHandle == null) {
return null;
}
return getNodeFromInternalInstanceHandle(
publicInstance.__internalInstanceHandle
);
}
var emptyObject = {};
{
@@ -28348,7 +28333,8 @@ function getInspectorDataForViewAtPoint(
) {
{
var closestInstance = null;
var fabricNode = getNodeFromPublicInstance(inspectedView);
var fabricNode =
ReactNativePrivateInterface.getNodeFromPublicInstance(inspectedView);
if (fabricNode) {
// For Fabric we can look up the instance handle directly and measure it.
@@ -940,7 +940,7 @@ eventPluginOrder = Array.prototype.slice.call([
"ReactNativeBridgeEventPlugin"
]);
recomputePluginOrdering();
var injectedNamesToPlugins$jscomp$inline_248 = {
var injectedNamesToPlugins$jscomp$inline_247 = {
ResponderEventPlugin: ResponderEventPlugin,
ReactNativeBridgeEventPlugin: {
eventTypes: {},
@@ -986,32 +986,32 @@ var injectedNamesToPlugins$jscomp$inline_248 = {
}
}
},
isOrderingDirty$jscomp$inline_249 = !1,
pluginName$jscomp$inline_250;
for (pluginName$jscomp$inline_250 in injectedNamesToPlugins$jscomp$inline_248)
isOrderingDirty$jscomp$inline_248 = !1,
pluginName$jscomp$inline_249;
for (pluginName$jscomp$inline_249 in injectedNamesToPlugins$jscomp$inline_247)
if (
injectedNamesToPlugins$jscomp$inline_248.hasOwnProperty(
pluginName$jscomp$inline_250
injectedNamesToPlugins$jscomp$inline_247.hasOwnProperty(
pluginName$jscomp$inline_249
)
) {
var pluginModule$jscomp$inline_251 =
injectedNamesToPlugins$jscomp$inline_248[pluginName$jscomp$inline_250];
var pluginModule$jscomp$inline_250 =
injectedNamesToPlugins$jscomp$inline_247[pluginName$jscomp$inline_249];
if (
!namesToPlugins.hasOwnProperty(pluginName$jscomp$inline_250) ||
namesToPlugins[pluginName$jscomp$inline_250] !==
pluginModule$jscomp$inline_251
!namesToPlugins.hasOwnProperty(pluginName$jscomp$inline_249) ||
namesToPlugins[pluginName$jscomp$inline_249] !==
pluginModule$jscomp$inline_250
) {
if (namesToPlugins[pluginName$jscomp$inline_250])
if (namesToPlugins[pluginName$jscomp$inline_249])
throw Error(
"EventPluginRegistry: Cannot inject two different event plugins using the same name, `" +
(pluginName$jscomp$inline_250 + "`.")
(pluginName$jscomp$inline_249 + "`.")
);
namesToPlugins[pluginName$jscomp$inline_250] =
pluginModule$jscomp$inline_251;
isOrderingDirty$jscomp$inline_249 = !0;
namesToPlugins[pluginName$jscomp$inline_249] =
pluginModule$jscomp$inline_250;
isOrderingDirty$jscomp$inline_248 = !0;
}
}
isOrderingDirty$jscomp$inline_249 && recomputePluginOrdering();
isOrderingDirty$jscomp$inline_248 && recomputePluginOrdering();
var instanceCache = new Map(),
instanceProps = new Map();
function getInstanceFromTag(tag) {
@@ -9597,21 +9597,19 @@ function findNodeHandle(componentOrHandle) {
null != componentOrHandle.canonical.nativeTag
)
return componentOrHandle.canonical.nativeTag;
var nativeTag = componentOrHandle.__nativeTag;
var nativeTag =
ReactNativePrivateInterface.getNativeTagFromPublicInstance(
componentOrHandle
);
if (nativeTag) return nativeTag;
componentOrHandle = findHostInstance(componentOrHandle);
return null == componentOrHandle
? componentOrHandle
: null != componentOrHandle._nativeTag
? componentOrHandle._nativeTag
: componentOrHandle.__nativeTag;
}
function getNodeFromPublicInstance(publicInstance) {
return null == publicInstance.__internalInstanceHandle
? null
: (publicInstance = publicInstance.__internalInstanceHandle) &&
publicInstance.stateNode &&
publicInstance.stateNode.node;
: ReactNativePrivateInterface.getNativeTagFromPublicInstance(
componentOrHandle
);
}
var emptyObject = {};
function createHierarchy(fiberHierarchy) {
@@ -9692,10 +9690,10 @@ batchedUpdatesImpl = function (fn, a) {
}
};
var roots = new Map(),
devToolsConfig$jscomp$inline_1111 = {
devToolsConfig$jscomp$inline_1108 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "18.3.0-next-f77099b6f-20230322",
version: "18.3.0-next-9c54b29b4-20230322",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
@@ -9710,11 +9708,11 @@ var roots = new Map(),
}.bind(null, findNodeHandle)
}
};
var internals$jscomp$inline_1361 = {
bundleType: devToolsConfig$jscomp$inline_1111.bundleType,
version: devToolsConfig$jscomp$inline_1111.version,
rendererPackageName: devToolsConfig$jscomp$inline_1111.rendererPackageName,
rendererConfig: devToolsConfig$jscomp$inline_1111.rendererConfig,
var internals$jscomp$inline_1358 = {
bundleType: devToolsConfig$jscomp$inline_1108.bundleType,
version: devToolsConfig$jscomp$inline_1108.version,
rendererPackageName: devToolsConfig$jscomp$inline_1108.rendererPackageName,
rendererConfig: devToolsConfig$jscomp$inline_1108.rendererConfig,
overrideHookState: null,
overrideHookStateDeletePath: null,
overrideHookStateRenamePath: null,
@@ -9730,26 +9728,26 @@ var internals$jscomp$inline_1361 = {
return null === fiber ? null : fiber.stateNode;
},
findFiberByHostInstance:
devToolsConfig$jscomp$inline_1111.findFiberByHostInstance ||
devToolsConfig$jscomp$inline_1108.findFiberByHostInstance ||
emptyFindFiberByHostInstance,
findHostInstancesForRefresh: null,
scheduleRefresh: null,
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-f77099b6f-20230322"
reconcilerVersion: "18.3.0-next-9c54b29b4-20230322"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1362 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
var hook$jscomp$inline_1359 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
if (
!hook$jscomp$inline_1362.isDisabled &&
hook$jscomp$inline_1362.supportsFiber
!hook$jscomp$inline_1359.isDisabled &&
hook$jscomp$inline_1359.supportsFiber
)
try {
(rendererID = hook$jscomp$inline_1362.inject(
internals$jscomp$inline_1361
(rendererID = hook$jscomp$inline_1359.inject(
internals$jscomp$inline_1358
)),
(injectedHook = hook$jscomp$inline_1362);
(injectedHook = hook$jscomp$inline_1359);
} catch (err) {}
}
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
@@ -9769,9 +9767,11 @@ exports.createPortal = function (children, containerTag) {
};
exports.dispatchCommand = function (handle, command, args) {
var nativeTag =
null != handle._nativeTag ? handle._nativeTag : handle.__nativeTag;
null != handle._nativeTag
? handle._nativeTag
: ReactNativePrivateInterface.getNativeTagFromPublicInstance(handle);
null != nativeTag &&
((handle = getNodeFromPublicInstance(handle)),
((handle = ReactNativePrivateInterface.getNodeFromPublicInstance(handle)),
null != handle
? nativeFabricUIManager.dispatchCommand(handle, command, args)
: ReactNativePrivateInterface.UIManager.dispatchViewManagerCommand(
@@ -9853,9 +9853,11 @@ exports.render = function (element, containerTag, callback) {
};
exports.sendAccessibilityEvent = function (handle, eventType) {
var nativeTag =
null != handle._nativeTag ? handle._nativeTag : handle.__nativeTag;
null != handle._nativeTag
? handle._nativeTag
: ReactNativePrivateInterface.getNativeTagFromPublicInstance(handle);
null != nativeTag &&
((handle = getNodeFromPublicInstance(handle)),
((handle = ReactNativePrivateInterface.getNodeFromPublicInstance(handle)),
null != handle
? nativeFabricUIManager.sendAccessibilityEvent(handle, eventType)
: ReactNativePrivateInterface.legacySendAccessibilityEvent(
@@ -951,7 +951,7 @@ eventPluginOrder = Array.prototype.slice.call([
"ReactNativeBridgeEventPlugin"
]);
recomputePluginOrdering();
var injectedNamesToPlugins$jscomp$inline_264 = {
var injectedNamesToPlugins$jscomp$inline_263 = {
ResponderEventPlugin: ResponderEventPlugin,
ReactNativeBridgeEventPlugin: {
eventTypes: {},
@@ -997,32 +997,32 @@ var injectedNamesToPlugins$jscomp$inline_264 = {
}
}
},
isOrderingDirty$jscomp$inline_265 = !1,
pluginName$jscomp$inline_266;
for (pluginName$jscomp$inline_266 in injectedNamesToPlugins$jscomp$inline_264)
isOrderingDirty$jscomp$inline_264 = !1,
pluginName$jscomp$inline_265;
for (pluginName$jscomp$inline_265 in injectedNamesToPlugins$jscomp$inline_263)
if (
injectedNamesToPlugins$jscomp$inline_264.hasOwnProperty(
pluginName$jscomp$inline_266
injectedNamesToPlugins$jscomp$inline_263.hasOwnProperty(
pluginName$jscomp$inline_265
)
) {
var pluginModule$jscomp$inline_267 =
injectedNamesToPlugins$jscomp$inline_264[pluginName$jscomp$inline_266];
var pluginModule$jscomp$inline_266 =
injectedNamesToPlugins$jscomp$inline_263[pluginName$jscomp$inline_265];
if (
!namesToPlugins.hasOwnProperty(pluginName$jscomp$inline_266) ||
namesToPlugins[pluginName$jscomp$inline_266] !==
pluginModule$jscomp$inline_267
!namesToPlugins.hasOwnProperty(pluginName$jscomp$inline_265) ||
namesToPlugins[pluginName$jscomp$inline_265] !==
pluginModule$jscomp$inline_266
) {
if (namesToPlugins[pluginName$jscomp$inline_266])
if (namesToPlugins[pluginName$jscomp$inline_265])
throw Error(
"EventPluginRegistry: Cannot inject two different event plugins using the same name, `" +
(pluginName$jscomp$inline_266 + "`.")
(pluginName$jscomp$inline_265 + "`.")
);
namesToPlugins[pluginName$jscomp$inline_266] =
pluginModule$jscomp$inline_267;
isOrderingDirty$jscomp$inline_265 = !0;
namesToPlugins[pluginName$jscomp$inline_265] =
pluginModule$jscomp$inline_266;
isOrderingDirty$jscomp$inline_264 = !0;
}
}
isOrderingDirty$jscomp$inline_265 && recomputePluginOrdering();
isOrderingDirty$jscomp$inline_264 && recomputePluginOrdering();
var instanceCache = new Map(),
instanceProps = new Map();
function getInstanceFromTag(tag) {
@@ -10305,21 +10305,19 @@ function findNodeHandle(componentOrHandle) {
null != componentOrHandle.canonical.nativeTag
)
return componentOrHandle.canonical.nativeTag;
var nativeTag = componentOrHandle.__nativeTag;
var nativeTag =
ReactNativePrivateInterface.getNativeTagFromPublicInstance(
componentOrHandle
);
if (nativeTag) return nativeTag;
componentOrHandle = findHostInstance(componentOrHandle);
return null == componentOrHandle
? componentOrHandle
: null != componentOrHandle._nativeTag
? componentOrHandle._nativeTag
: componentOrHandle.__nativeTag;
}
function getNodeFromPublicInstance(publicInstance) {
return null == publicInstance.__internalInstanceHandle
? null
: (publicInstance = publicInstance.__internalInstanceHandle) &&
publicInstance.stateNode &&
publicInstance.stateNode.node;
: ReactNativePrivateInterface.getNativeTagFromPublicInstance(
componentOrHandle
);
}
var emptyObject = {};
function createHierarchy(fiberHierarchy) {
@@ -10400,10 +10398,10 @@ batchedUpdatesImpl = function (fn, a) {
}
};
var roots = new Map(),
devToolsConfig$jscomp$inline_1190 = {
devToolsConfig$jscomp$inline_1187 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "18.3.0-next-f77099b6f-20230322",
version: "18.3.0-next-9c54b29b4-20230322",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForViewTag: function () {
@@ -10432,10 +10430,10 @@ var roots = new Map(),
} catch (err) {}
return hook.checkDCE ? !0 : !1;
})({
bundleType: devToolsConfig$jscomp$inline_1190.bundleType,
version: devToolsConfig$jscomp$inline_1190.version,
rendererPackageName: devToolsConfig$jscomp$inline_1190.rendererPackageName,
rendererConfig: devToolsConfig$jscomp$inline_1190.rendererConfig,
bundleType: devToolsConfig$jscomp$inline_1187.bundleType,
version: devToolsConfig$jscomp$inline_1187.version,
rendererPackageName: devToolsConfig$jscomp$inline_1187.rendererPackageName,
rendererConfig: devToolsConfig$jscomp$inline_1187.rendererConfig,
overrideHookState: null,
overrideHookStateDeletePath: null,
overrideHookStateRenamePath: null,
@@ -10451,14 +10449,14 @@ var roots = new Map(),
return null === fiber ? null : fiber.stateNode;
},
findFiberByHostInstance:
devToolsConfig$jscomp$inline_1190.findFiberByHostInstance ||
devToolsConfig$jscomp$inline_1187.findFiberByHostInstance ||
emptyFindFiberByHostInstance,
findHostInstancesForRefresh: null,
scheduleRefresh: null,
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-next-f77099b6f-20230322"
reconcilerVersion: "18.3.0-next-9c54b29b4-20230322"
});
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
computeComponentStackForErrorReporting: function (reactTag) {
@@ -10477,9 +10475,11 @@ exports.createPortal = function (children, containerTag) {
};
exports.dispatchCommand = function (handle, command, args) {
var nativeTag =
null != handle._nativeTag ? handle._nativeTag : handle.__nativeTag;
null != handle._nativeTag
? handle._nativeTag
: ReactNativePrivateInterface.getNativeTagFromPublicInstance(handle);
null != nativeTag &&
((handle = getNodeFromPublicInstance(handle)),
((handle = ReactNativePrivateInterface.getNodeFromPublicInstance(handle)),
null != handle
? nativeFabricUIManager.dispatchCommand(handle, command, args)
: ReactNativePrivateInterface.UIManager.dispatchViewManagerCommand(
@@ -10568,9 +10568,11 @@ exports.render = function (element, containerTag, callback) {
};
exports.sendAccessibilityEvent = function (handle, eventType) {
var nativeTag =
null != handle._nativeTag ? handle._nativeTag : handle.__nativeTag;
null != handle._nativeTag
? handle._nativeTag
: ReactNativePrivateInterface.getNativeTagFromPublicInstance(handle);
null != nativeTag &&
((handle = getNodeFromPublicInstance(handle)),
((handle = ReactNativePrivateInterface.getNodeFromPublicInstance(handle)),
null != handle
? nativeFabricUIManager.sendAccessibilityEvent(handle, eventType)
: ReactNativePrivateInterface.legacySendAccessibilityEvent(