feat[Fabric/Paper]: support isChildPublicInstance api method (#27783)

Adds `isChildPublicInstance` method to both renderers (Fabric and
Paper), which will receive 2 public instances and return if first
argument is an ancestor of the second, based on fibers.

This will be used as a fallback when DOM node APIs are not available:
for Paper renderer or for Fabric without DOM node APIs.

How it is going to be used: to determine which `AppContainer` component
in RN is responsible for highlighting an inspected element on the
screen.

DiffTrain build for commit https://github.com/facebook/react/commit/1729b499ed8cd456ef3d8bccd413cdecd9931abc.
This commit is contained in:
hoxyq
2023-12-04 17:27:01 +00:00
parent c114997251
commit 73da448d35
13 changed files with 305 additions and 25 deletions
@@ -25474,7 +25474,7 @@ if (__DEV__) {
return root;
}
var ReactVersion = "18.3.0-canary-e3fb6ac86-20231204";
var ReactVersion = "18.3.0-canary-1729b499e-20231204";
// Might add PROFILE later.
@@ -9083,7 +9083,7 @@ var devToolsConfig$jscomp$inline_1033 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-e3fb6ac86-20231204",
version: "18.3.0-canary-1729b499e-20231204",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1226 = {
@@ -9114,7 +9114,7 @@ var internals$jscomp$inline_1226 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-e3fb6ac86-20231204"
reconcilerVersion: "18.3.0-canary-1729b499e-20231204"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1227 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -9509,7 +9509,7 @@ var devToolsConfig$jscomp$inline_1075 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-e3fb6ac86-20231204",
version: "18.3.0-canary-1729b499e-20231204",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1267 = {
@@ -9540,7 +9540,7 @@ var internals$jscomp$inline_1267 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-e3fb6ac86-20231204"
reconcilerVersion: "18.3.0-canary-1729b499e-20231204"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1268 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -24,7 +24,7 @@ if (__DEV__) {
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = "18.3.0-canary-e3fb6ac86-20231204";
var ReactVersion = "18.3.0-canary-1729b499e-20231204";
// ATTENTION
// When adding new symbols to this file,
@@ -580,4 +580,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-e3fb6ac86-20231204";
exports.version = "18.3.0-canary-1729b499e-20231204";
@@ -576,7 +576,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-e3fb6ac86-20231204";
exports.version = "18.3.0-canary-1729b499e-20231204";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
@@ -1 +1 @@
e3fb6ac862e895d7e491628589fca8300f308887
1729b499ed8cd456ef3d8bccd413cdecd9931abc
@@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<aeb13744feb3c4d52877eeb7f7905a51>>
* @generated SignedSource<<685bf7c576463dfbb4cf704d94b8c71b>>
*/
"use strict";
@@ -5862,6 +5862,20 @@ to return true:wantsResponderID| |
return null;
}
function doesFiberContain(parentFiber, childFiber) {
var node = childFiber;
var parentFiberAlternate = parentFiber.alternate;
while (node !== null) {
if (node === parentFiber || node === parentFiberAlternate) {
return true;
}
node = node.return;
}
return false;
}
function describeBuiltInComponentFrame(name, source, ownerFn) {
{
@@ -27815,7 +27829,7 @@ to return true:wantsResponderID| |
return root;
}
var ReactVersion = "18.3.0-canary-c34d6f72";
var ReactVersion = "18.3.0-canary-ad95fe0f";
function createPortal$1(
children,
@@ -28357,6 +28371,158 @@ to return true:wantsResponderID| |
return instanceCache.get(tag) || null;
}
/**
* In the future, we should cleanup callbacks by cancelling them instead of
* using this.
*/
function mountSafeCallback_NOT_REALLY_SAFE(context, callback) {
return function () {
if (!callback) {
return undefined;
} // This protects against createClass() components.
// We don't know if there is code depending on it.
// We intentionally don't use isMounted() because even accessing
// isMounted property on a React ES6 class will trigger a warning.
if (typeof context.__isMounted === "boolean") {
if (!context.__isMounted) {
return undefined;
}
} // FIXME: there used to be other branches that protected
// against unmounted host components. But RN host components don't
// define isMounted() anymore, so those checks didn't do anything.
// They caused false positive warning noise so we removed them:
// https://github.com/facebook/react-native/issues/18868#issuecomment-413579095
// However, this means that the callback is NOT guaranteed to be safe
// for host components. The solution we should implement is to make
// UIManager.measure() and similar calls truly cancelable. Then we
// can change our own code calling them to cancel when something unmounts.
return callback.apply(context, arguments);
};
}
function warnForStyleProps(props, validAttributes) {
{
for (var key in validAttributes.style) {
if (!(validAttributes[key] || props[key] === undefined)) {
error(
"You are setting the style `{ %s" +
": ... }` as a prop. You " +
"should nest it in a style object. " +
"E.g. `{ style: { %s" +
": ... } }`",
key,
key
);
}
}
}
}
var ReactNativeFiberHostComponent = /*#__PURE__*/ (function () {
function ReactNativeFiberHostComponent(
tag,
viewConfig,
internalInstanceHandleDEV
) {
this._children = void 0;
this._nativeTag = void 0;
this._internalFiberInstanceHandleDEV = void 0;
this.viewConfig = void 0;
this._nativeTag = tag;
this._children = [];
this.viewConfig = viewConfig;
{
this._internalFiberInstanceHandleDEV = internalInstanceHandleDEV;
}
}
var _proto = ReactNativeFiberHostComponent.prototype;
_proto.blur = function blur() {
ReactNativePrivateInterface.TextInputState.blurTextInput(this);
};
_proto.focus = function focus() {
ReactNativePrivateInterface.TextInputState.focusTextInput(this);
};
_proto.measure = function measure(callback) {
ReactNativePrivateInterface.UIManager.measure(
this._nativeTag,
mountSafeCallback_NOT_REALLY_SAFE(this, callback)
);
};
_proto.measureInWindow = function measureInWindow(callback) {
ReactNativePrivateInterface.UIManager.measureInWindow(
this._nativeTag,
mountSafeCallback_NOT_REALLY_SAFE(this, callback)
);
};
_proto.measureLayout = function measureLayout(
relativeToNativeNode,
onSuccess,
onFail
/* currently unused */
) {
var relativeNode;
if (typeof relativeToNativeNode === "number") {
// Already a node handle
relativeNode = relativeToNativeNode;
} else {
var nativeNode = relativeToNativeNode;
if (nativeNode._nativeTag) {
relativeNode = nativeNode._nativeTag;
}
}
if (relativeNode == null) {
{
error(
"Warning: ref.measureLayout must be called with a node handle or a ref to a native component."
);
}
return;
}
ReactNativePrivateInterface.UIManager.measureLayout(
this._nativeTag,
relativeNode,
mountSafeCallback_NOT_REALLY_SAFE(this, onFail),
mountSafeCallback_NOT_REALLY_SAFE(this, onSuccess)
);
};
_proto.setNativeProps = function setNativeProps(nativeProps) {
{
warnForStyleProps(nativeProps, this.viewConfig.validAttributes);
}
var updatePayload = create(
nativeProps,
this.viewConfig.validAttributes
); // Avoid the overhead of bridge calls if there's no update.
// This is an expensive no-op for Android, and causes an unnecessary
// view invalidation for certain components (eg RCTTextInput) on iOS.
if (updatePayload != null) {
ReactNativePrivateInterface.UIManager.updateView(
this._nativeTag,
this.viewConfig.uiViewClassName,
updatePayload
);
}
};
return ReactNativeFiberHostComponent;
})();
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
function findHostInstance_DEPRECATED(componentOrHandle) {
{
@@ -28545,6 +28711,49 @@ to return true:wantsResponderID| |
internalInstanceHandle.stateNode && // $FlowExpectedError[incompatible-use]
internalInstanceHandle.stateNode.node
);
} // Remove this once Paper is no longer supported and DOM Node API are enabled by default in RN.
function isChildPublicInstance(parentInstance, childInstance) {
{
// 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;
}
var parentInternalInstanceHandle =
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
parentInstance
);
var childInternalInstanceHandle =
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
childInstance
); // Fabric
if (
parentInternalInstanceHandle != null &&
childInternalInstanceHandle != null
) {
return doesFiberContain(
parentInternalInstanceHandle,
childInternalInstanceHandle
);
}
return false;
}
}
var emptyObject = {};
@@ -28859,6 +29068,7 @@ to return true:wantsResponderID| |
getNodeFromInternalInstanceHandle;
exports.getPublicInstanceFromInternalInstanceHandle =
getPublicInstanceFromInternalInstanceHandle;
exports.isChildPublicInstance = isChildPublicInstance;
exports.render = render;
exports.sendAccessibilityEvent = sendAccessibilityEvent;
exports.stopSurface = stopSurface;
@@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<3d433092fb21fe655546ab8cc86bfe96>>
* @generated SignedSource<<5f82e29b047fb91d2b0612c4bb92f552>>
*/
"use strict";
@@ -9544,7 +9544,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1048 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "18.3.0-canary-a0c4da55",
version: "18.3.0-canary-c1e14826",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -9587,7 +9587,7 @@ var internals$jscomp$inline_1290 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-a0c4da55"
reconcilerVersion: "18.3.0-canary-c1e14826"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1291 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -9658,6 +9658,9 @@ exports.getPublicInstanceFromInternalInstanceHandle = function (
instance.publicInstance)
: getPublicInstance(internalInstanceHandle.stateNode);
};
exports.isChildPublicInstance = function () {
throw Error("isChildPublicInstance() is not available in production.");
};
exports.render = function (element, containerTag, callback, concurrentRoot) {
var root = roots.get(containerTag);
root ||
@@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<c84472616bec5f450a6873c637335a4d>>
* @generated SignedSource<<819b37c0740158533aae99ef65b5d190>>
*/
"use strict";
@@ -10246,7 +10246,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1126 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "18.3.0-canary-e91c485a",
version: "18.3.0-canary-b8e7c812",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -10302,7 +10302,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-e91c485a"
reconcilerVersion: "18.3.0-canary-b8e7c812"
});
exports.createPortal = function (children, containerTag) {
return createPortal$1(
@@ -10360,6 +10360,9 @@ exports.getPublicInstanceFromInternalInstanceHandle = function (
instance.publicInstance)
: getPublicInstance(internalInstanceHandle.stateNode);
};
exports.isChildPublicInstance = function () {
throw Error("isChildPublicInstance() is not available in production.");
};
exports.render = function (element, containerTag, callback, concurrentRoot) {
var root = roots.get(containerTag);
root ||
@@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<ce5fd2521d2e9fc4c77333a98ac6ecb4>>
* @generated SignedSource<<d24e5265ff25936497dfc29885a7ed06>>
*/
"use strict";
@@ -3604,6 +3604,20 @@ to return true:wantsResponderID| |
return null;
}
function doesFiberContain(parentFiber, childFiber) {
var node = childFiber;
var parentFiberAlternate = parentFiber.alternate;
while (node !== null) {
if (node === parentFiber || node === parentFiberAlternate) {
return true;
}
node = node.return;
}
return false;
}
// Modules provided by RN:
var emptyObject$1 = {};
@@ -28256,7 +28270,7 @@ to return true:wantsResponderID| |
return root;
}
var ReactVersion = "18.3.0-canary-285f1cc2";
var ReactVersion = "18.3.0-canary-6d7633fe";
function createPortal$1(
children,
@@ -28980,6 +28994,49 @@ to return true:wantsResponderID| |
internalInstanceHandle.stateNode && // $FlowExpectedError[incompatible-use]
internalInstanceHandle.stateNode.node
);
} // Remove this once Paper is no longer supported and DOM Node API are enabled by default in RN.
function isChildPublicInstance(parentInstance, childInstance) {
{
// 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;
}
var parentInternalInstanceHandle =
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
parentInstance
);
var childInternalInstanceHandle =
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
childInstance
); // Fabric
if (
parentInternalInstanceHandle != null &&
childInternalInstanceHandle != null
) {
return doesFiberContain(
parentInternalInstanceHandle,
childInternalInstanceHandle
);
}
return false;
}
}
var emptyObject = {};
@@ -29307,6 +29364,7 @@ to return true:wantsResponderID| |
exports.findHostInstance_DEPRECATED = findHostInstance_DEPRECATED;
exports.findNodeHandle = findNodeHandle;
exports.getInspectorDataForInstance = getInspectorDataForInstance;
exports.isChildPublicInstance = isChildPublicInstance;
exports.render = render;
exports.sendAccessibilityEvent = sendAccessibilityEvent;
exports.unmountComponentAtNode = unmountComponentAtNode;
@@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<7fdeaf4f918aca9cf091153ffddbae9a>>
* @generated SignedSource<<863e55acd5e0f90afebe249734c95bac>>
*/
"use strict";
@@ -9766,7 +9766,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1111 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "18.3.0-canary-5ba98bbb",
version: "18.3.0-canary-b9d34249",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -9809,7 +9809,7 @@ var internals$jscomp$inline_1367 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-5ba98bbb"
reconcilerVersion: "18.3.0-canary-b9d34249"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1368 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -9865,6 +9865,9 @@ exports.findHostInstance_DEPRECATED = function (componentOrHandle) {
};
exports.findNodeHandle = findNodeHandle;
exports.getInspectorDataForInstance = getInspectorDataForInstance;
exports.isChildPublicInstance = function () {
throw Error("isChildPublicInstance() is not available in production.");
};
exports.render = function (element, containerTag, callback) {
var root = roots.get(containerTag);
if (!root) {
@@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<c0c76c904ba8465467031fe724931223>>
* @generated SignedSource<<36792d6bd27d5d504c52b9ade8416d95>>
*/
"use strict";
@@ -10468,7 +10468,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1189 = {
findFiberByHostInstance: getInstanceFromTag,
bundleType: 0,
version: "18.3.0-canary-0d007843",
version: "18.3.0-canary-fea3cad9",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -10524,7 +10524,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-0d007843"
reconcilerVersion: "18.3.0-canary-fea3cad9"
});
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
computeComponentStackForErrorReporting: function (reactTag) {
@@ -10567,6 +10567,9 @@ exports.findHostInstance_DEPRECATED = function (componentOrHandle) {
};
exports.findNodeHandle = findNodeHandle;
exports.getInspectorDataForInstance = getInspectorDataForInstance;
exports.isChildPublicInstance = function () {
throw Error("isChildPublicInstance() is not available in production.");
};
exports.render = function (element, containerTag, callback) {
var root = roots.get(containerTag);
if (!root) {