Skip to content

Commit 73da448

Browse files
committed
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 1729b49.
1 parent c114997 commit 73da448

13 files changed

+305
-25
lines changed

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25474,7 +25474,7 @@ if (__DEV__) {
2547425474
return root;
2547525475
}
2547625476

25477-
var ReactVersion = "18.3.0-canary-e3fb6ac86-20231204";
25477+
var ReactVersion = "18.3.0-canary-1729b499e-20231204";
2547825478

2547925479
// Might add PROFILE later.
2548025480

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9083,7 +9083,7 @@ var devToolsConfig$jscomp$inline_1033 = {
90839083
throw Error("TestRenderer does not support findFiberByHostInstance()");
90849084
},
90859085
bundleType: 0,
9086-
version: "18.3.0-canary-e3fb6ac86-20231204",
9086+
version: "18.3.0-canary-1729b499e-20231204",
90879087
rendererPackageName: "react-test-renderer"
90889088
};
90899089
var internals$jscomp$inline_1226 = {
@@ -9114,7 +9114,7 @@ var internals$jscomp$inline_1226 = {
91149114
scheduleRoot: null,
91159115
setRefreshHandler: null,
91169116
getCurrentFiber: null,
9117-
reconcilerVersion: "18.3.0-canary-e3fb6ac86-20231204"
9117+
reconcilerVersion: "18.3.0-canary-1729b499e-20231204"
91189118
};
91199119
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
91209120
var hook$jscomp$inline_1227 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9509,7 +9509,7 @@ var devToolsConfig$jscomp$inline_1075 = {
95099509
throw Error("TestRenderer does not support findFiberByHostInstance()");
95109510
},
95119511
bundleType: 0,
9512-
version: "18.3.0-canary-e3fb6ac86-20231204",
9512+
version: "18.3.0-canary-1729b499e-20231204",
95139513
rendererPackageName: "react-test-renderer"
95149514
};
95159515
var internals$jscomp$inline_1267 = {
@@ -9540,7 +9540,7 @@ var internals$jscomp$inline_1267 = {
95409540
scheduleRoot: null,
95419541
setRefreshHandler: null,
95429542
getCurrentFiber: null,
9543-
reconcilerVersion: "18.3.0-canary-e3fb6ac86-20231204"
9543+
reconcilerVersion: "18.3.0-canary-1729b499e-20231204"
95449544
};
95459545
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
95469546
var hook$jscomp$inline_1268 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (__DEV__) {
2424
) {
2525
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
2626
}
27-
var ReactVersion = "18.3.0-canary-e3fb6ac86-20231204";
27+
var ReactVersion = "18.3.0-canary-1729b499e-20231204";
2828

2929
// ATTENTION
3030
// When adding new symbols to this file,

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,4 @@ exports.useSyncExternalStore = function (
580580
exports.useTransition = function () {
581581
return ReactCurrentDispatcher.current.useTransition();
582582
};
583-
exports.version = "18.3.0-canary-e3fb6ac86-20231204";
583+
exports.version = "18.3.0-canary-1729b499e-20231204";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ exports.useSyncExternalStore = function (
576576
exports.useTransition = function () {
577577
return ReactCurrentDispatcher.current.useTransition();
578578
};
579-
exports.version = "18.3.0-canary-e3fb6ac86-20231204";
579+
exports.version = "18.3.0-canary-1729b499e-20231204";
580580
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
581581
"function" ===
582582
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e3fb6ac862e895d7e491628589fca8300f308887
1+
1729b499ed8cd456ef3d8bccd413cdecd9931abc

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js

+212-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<aeb13744feb3c4d52877eeb7f7905a51>>
10+
* @generated SignedSource<<685bf7c576463dfbb4cf704d94b8c71b>>
1111
*/
1212

1313
"use strict";
@@ -5862,6 +5862,20 @@ to return true:wantsResponderID| |
58625862

58635863
return null;
58645864
}
5865+
function doesFiberContain(parentFiber, childFiber) {
5866+
var node = childFiber;
5867+
var parentFiberAlternate = parentFiber.alternate;
5868+
5869+
while (node !== null) {
5870+
if (node === parentFiber || node === parentFiberAlternate) {
5871+
return true;
5872+
}
5873+
5874+
node = node.return;
5875+
}
5876+
5877+
return false;
5878+
}
58655879

58665880
function describeBuiltInComponentFrame(name, source, ownerFn) {
58675881
{
@@ -27815,7 +27829,7 @@ to return true:wantsResponderID| |
2781527829
return root;
2781627830
}
2781727831

27818-
var ReactVersion = "18.3.0-canary-c34d6f72";
27832+
var ReactVersion = "18.3.0-canary-ad95fe0f";
2781927833

2782027834
function createPortal$1(
2782127835
children,
@@ -28357,6 +28371,158 @@ to return true:wantsResponderID| |
2835728371
return instanceCache.get(tag) || null;
2835828372
}
2835928373

28374+
/**
28375+
* In the future, we should cleanup callbacks by cancelling them instead of
28376+
* using this.
28377+
*/
28378+
function mountSafeCallback_NOT_REALLY_SAFE(context, callback) {
28379+
return function () {
28380+
if (!callback) {
28381+
return undefined;
28382+
} // This protects against createClass() components.
28383+
// We don't know if there is code depending on it.
28384+
// We intentionally don't use isMounted() because even accessing
28385+
// isMounted property on a React ES6 class will trigger a warning.
28386+
28387+
if (typeof context.__isMounted === "boolean") {
28388+
if (!context.__isMounted) {
28389+
return undefined;
28390+
}
28391+
} // FIXME: there used to be other branches that protected
28392+
// against unmounted host components. But RN host components don't
28393+
// define isMounted() anymore, so those checks didn't do anything.
28394+
// They caused false positive warning noise so we removed them:
28395+
// https://github.com/facebook/react-native/issues/18868#issuecomment-413579095
28396+
// However, this means that the callback is NOT guaranteed to be safe
28397+
// for host components. The solution we should implement is to make
28398+
// UIManager.measure() and similar calls truly cancelable. Then we
28399+
// can change our own code calling them to cancel when something unmounts.
28400+
28401+
return callback.apply(context, arguments);
28402+
};
28403+
}
28404+
function warnForStyleProps(props, validAttributes) {
28405+
{
28406+
for (var key in validAttributes.style) {
28407+
if (!(validAttributes[key] || props[key] === undefined)) {
28408+
error(
28409+
"You are setting the style `{ %s" +
28410+
": ... }` as a prop. You " +
28411+
"should nest it in a style object. " +
28412+
"E.g. `{ style: { %s" +
28413+
": ... } }`",
28414+
key,
28415+
key
28416+
);
28417+
}
28418+
}
28419+
}
28420+
}
28421+
28422+
var ReactNativeFiberHostComponent = /*#__PURE__*/ (function () {
28423+
function ReactNativeFiberHostComponent(
28424+
tag,
28425+
viewConfig,
28426+
internalInstanceHandleDEV
28427+
) {
28428+
this._children = void 0;
28429+
this._nativeTag = void 0;
28430+
this._internalFiberInstanceHandleDEV = void 0;
28431+
this.viewConfig = void 0;
28432+
this._nativeTag = tag;
28433+
this._children = [];
28434+
this.viewConfig = viewConfig;
28435+
28436+
{
28437+
this._internalFiberInstanceHandleDEV = internalInstanceHandleDEV;
28438+
}
28439+
}
28440+
28441+
var _proto = ReactNativeFiberHostComponent.prototype;
28442+
28443+
_proto.blur = function blur() {
28444+
ReactNativePrivateInterface.TextInputState.blurTextInput(this);
28445+
};
28446+
28447+
_proto.focus = function focus() {
28448+
ReactNativePrivateInterface.TextInputState.focusTextInput(this);
28449+
};
28450+
28451+
_proto.measure = function measure(callback) {
28452+
ReactNativePrivateInterface.UIManager.measure(
28453+
this._nativeTag,
28454+
mountSafeCallback_NOT_REALLY_SAFE(this, callback)
28455+
);
28456+
};
28457+
28458+
_proto.measureInWindow = function measureInWindow(callback) {
28459+
ReactNativePrivateInterface.UIManager.measureInWindow(
28460+
this._nativeTag,
28461+
mountSafeCallback_NOT_REALLY_SAFE(this, callback)
28462+
);
28463+
};
28464+
28465+
_proto.measureLayout = function measureLayout(
28466+
relativeToNativeNode,
28467+
onSuccess,
28468+
onFail
28469+
/* currently unused */
28470+
) {
28471+
var relativeNode;
28472+
28473+
if (typeof relativeToNativeNode === "number") {
28474+
// Already a node handle
28475+
relativeNode = relativeToNativeNode;
28476+
} else {
28477+
var nativeNode = relativeToNativeNode;
28478+
28479+
if (nativeNode._nativeTag) {
28480+
relativeNode = nativeNode._nativeTag;
28481+
}
28482+
}
28483+
28484+
if (relativeNode == null) {
28485+
{
28486+
error(
28487+
"Warning: ref.measureLayout must be called with a node handle or a ref to a native component."
28488+
);
28489+
}
28490+
28491+
return;
28492+
}
28493+
28494+
ReactNativePrivateInterface.UIManager.measureLayout(
28495+
this._nativeTag,
28496+
relativeNode,
28497+
mountSafeCallback_NOT_REALLY_SAFE(this, onFail),
28498+
mountSafeCallback_NOT_REALLY_SAFE(this, onSuccess)
28499+
);
28500+
};
28501+
28502+
_proto.setNativeProps = function setNativeProps(nativeProps) {
28503+
{
28504+
warnForStyleProps(nativeProps, this.viewConfig.validAttributes);
28505+
}
28506+
28507+
var updatePayload = create(
28508+
nativeProps,
28509+
this.viewConfig.validAttributes
28510+
); // Avoid the overhead of bridge calls if there's no update.
28511+
// This is an expensive no-op for Android, and causes an unnecessary
28512+
// view invalidation for certain components (eg RCTTextInput) on iOS.
28513+
28514+
if (updatePayload != null) {
28515+
ReactNativePrivateInterface.UIManager.updateView(
28516+
this._nativeTag,
28517+
this.viewConfig.uiViewClassName,
28518+
updatePayload
28519+
);
28520+
}
28521+
};
28522+
28523+
return ReactNativeFiberHostComponent;
28524+
})();
28525+
2836028526
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
2836128527
function findHostInstance_DEPRECATED(componentOrHandle) {
2836228528
{
@@ -28545,6 +28711,49 @@ to return true:wantsResponderID| |
2854528711
internalInstanceHandle.stateNode && // $FlowExpectedError[incompatible-use]
2854628712
internalInstanceHandle.stateNode.node
2854728713
);
28714+
} // Remove this once Paper is no longer supported and DOM Node API are enabled by default in RN.
28715+
28716+
function isChildPublicInstance(parentInstance, childInstance) {
28717+
{
28718+
// Paper
28719+
if (
28720+
parentInstance instanceof ReactNativeFiberHostComponent ||
28721+
childInstance instanceof ReactNativeFiberHostComponent
28722+
) {
28723+
if (
28724+
parentInstance instanceof ReactNativeFiberHostComponent &&
28725+
childInstance instanceof ReactNativeFiberHostComponent
28726+
) {
28727+
return doesFiberContain(
28728+
parentInstance._internalFiberInstanceHandleDEV,
28729+
childInstance._internalFiberInstanceHandleDEV
28730+
);
28731+
} // Means that one instance is from Fabric and other is from Paper.
28732+
28733+
return false;
28734+
}
28735+
28736+
var parentInternalInstanceHandle =
28737+
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
28738+
parentInstance
28739+
);
28740+
var childInternalInstanceHandle =
28741+
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
28742+
childInstance
28743+
); // Fabric
28744+
28745+
if (
28746+
parentInternalInstanceHandle != null &&
28747+
childInternalInstanceHandle != null
28748+
) {
28749+
return doesFiberContain(
28750+
parentInternalInstanceHandle,
28751+
childInternalInstanceHandle
28752+
);
28753+
}
28754+
28755+
return false;
28756+
}
2854828757
}
2854928758

2855028759
var emptyObject = {};
@@ -28859,6 +29068,7 @@ to return true:wantsResponderID| |
2885929068
getNodeFromInternalInstanceHandle;
2886029069
exports.getPublicInstanceFromInternalInstanceHandle =
2886129070
getPublicInstanceFromInternalInstanceHandle;
29071+
exports.isChildPublicInstance = isChildPublicInstance;
2886229072
exports.render = render;
2886329073
exports.sendAccessibilityEvent = sendAccessibilityEvent;
2886429074
exports.stopSurface = stopSurface;

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<3d433092fb21fe655546ab8cc86bfe96>>
10+
* @generated SignedSource<<5f82e29b047fb91d2b0612c4bb92f552>>
1111
*/
1212

1313
"use strict";
@@ -9544,7 +9544,7 @@ var roots = new Map(),
95449544
devToolsConfig$jscomp$inline_1048 = {
95459545
findFiberByHostInstance: getInstanceFromNode,
95469546
bundleType: 0,
9547-
version: "18.3.0-canary-a0c4da55",
9547+
version: "18.3.0-canary-c1e14826",
95489548
rendererPackageName: "react-native-renderer",
95499549
rendererConfig: {
95509550
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -9587,7 +9587,7 @@ var internals$jscomp$inline_1290 = {
95879587
scheduleRoot: null,
95889588
setRefreshHandler: null,
95899589
getCurrentFiber: null,
9590-
reconcilerVersion: "18.3.0-canary-a0c4da55"
9590+
reconcilerVersion: "18.3.0-canary-c1e14826"
95919591
};
95929592
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
95939593
var hook$jscomp$inline_1291 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -9658,6 +9658,9 @@ exports.getPublicInstanceFromInternalInstanceHandle = function (
96589658
instance.publicInstance)
96599659
: getPublicInstance(internalInstanceHandle.stateNode);
96609660
};
9661+
exports.isChildPublicInstance = function () {
9662+
throw Error("isChildPublicInstance() is not available in production.");
9663+
};
96619664
exports.render = function (element, containerTag, callback, concurrentRoot) {
96629665
var root = roots.get(containerTag);
96639666
root ||

0 commit comments

Comments
 (0)