Skip to content

Commit 997f060

Browse files
Ruslan Lesiutinfacebook-github-bot
Ruslan Lesiutin
authored andcommitted
fix: patch public renderer implementations to include isChildPublicInstance
Summary: Changelog: [Internal] Manually patching public React renderers artifacts to include `isChildPublicInstance` method, which was added in facebook/react#27783. To identifly the required changes in code I've ran a diff for 2 commits: 1. The one with the changes 2. Its parent FB implementation were synced in D51816108. Differential Revision: D52697885 fbshipit-source-id: e68baafbf9a7b3232375ab1db2560158c03641f8
1 parent 1514e0e commit 997f060

File tree

6 files changed

+124
-4
lines changed

6 files changed

+124
-4
lines changed

packages/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js

+56-1
Original file line numberDiff line numberDiff line change
@@ -3388,6 +3388,20 @@ function findCurrentHostFiberImpl(node) {
33883388

33893389
return null;
33903390
}
3391+
function doesFiberContain(parentFiber, childFiber) {
3392+
var node = childFiber;
3393+
var parentFiberAlternate = parentFiber.alternate;
3394+
3395+
while (node !== null) {
3396+
if (node === parentFiber || node === parentFiberAlternate) {
3397+
return true;
3398+
}
3399+
3400+
node = node.return;
3401+
}
3402+
3403+
return false;
3404+
}
33913405

33923406
/**
33933407
* In the future, we should cleanup callbacks by cancelling them instead of
@@ -24331,6 +24345,46 @@ function sendAccessibilityEvent(handle, eventType) {
2433124345
}
2433224346
}
2433324347

24348+
function isChildPublicInstance(parentInstance, childInstance) {
24349+
{
24350+
// Paper
24351+
if (
24352+
// $FlowExpectedError[incompatible-type]
24353+
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
24354+
parentInstance._internalFiberInstanceHandleDEV && // $FlowExpectedError[incompatible-type]
24355+
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
24356+
childInstance._internalFiberInstanceHandleDEV
24357+
) {
24358+
return doesFiberContain(
24359+
// $FlowExpectedError[incompatible-call]
24360+
parentInstance._internalFiberInstanceHandleDEV, // $FlowExpectedError[incompatible-call]
24361+
childInstance._internalFiberInstanceHandleDEV
24362+
);
24363+
}
24364+
24365+
var parentInternalInstanceHandle = // $FlowExpectedError[incompatible-call] Type for parentInstance should have been PublicInstance from ReactFiberConfigFabric.
24366+
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
24367+
parentInstance
24368+
);
24369+
var childInternalInstanceHandle = // $FlowExpectedError[incompatible-call] Type for childInstance should have been PublicInstance from ReactFiberConfigFabric.
24370+
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
24371+
childInstance
24372+
); // Fabric
24373+
24374+
if (
24375+
parentInternalInstanceHandle != null &&
24376+
childInternalInstanceHandle != null
24377+
) {
24378+
return doesFiberContain(
24379+
parentInternalInstanceHandle,
24380+
childInternalInstanceHandle
24381+
);
24382+
} // Means that one instance is from Fabric and other is from Paper.
24383+
24384+
return false;
24385+
}
24386+
}
24387+
2433424388
function onRecoverableError(error$1) {
2433524389
// TODO: Expose onRecoverableError option to userspace
2433624390
// eslint-disable-next-line react-internal/no-production-logging, react-internal/warning-args
@@ -24401,6 +24455,7 @@ exports.createPortal = createPortal$1;
2440124455
exports.dispatchCommand = dispatchCommand;
2440224456
exports.findHostInstance_DEPRECATED = findHostInstance_DEPRECATED;
2440324457
exports.findNodeHandle = findNodeHandle;
24458+
exports.isChildPublicInstance = isChildPublicInstance;
2440424459
exports.render = render;
2440524460
exports.sendAccessibilityEvent = sendAccessibilityEvent;
2440624461
exports.stopSurface = stopSurface;
@@ -24414,6 +24469,6 @@ if (
2441424469
) {
2441524470
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
2441624471
}
24417-
24472+
2441824473
})();
2441924474
}

packages/react-native/Libraries/Renderer/implementations/ReactFabric-prod.js

+3
Original file line numberDiff line numberDiff line change
@@ -8386,6 +8386,9 @@ exports.findHostInstance_DEPRECATED = function(componentOrHandle) {
83868386
};
83878387
exports.findNodeHandle = findNodeHandle;
83888388
exports.getInspectorDataForInstance = void 0;
8389+
exports.isChildPublicInstance = function () {
8390+
throw Error("isChildPublicInstance() is not available in production.");
8391+
};
83898392
exports.render = function(element, containerTag, callback, concurrentRoot) {
83908393
var root = roots.get(containerTag);
83918394
root ||

packages/react-native/Libraries/Renderer/implementations/ReactFabric-profiling.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8863,6 +8863,9 @@ exports.findHostInstance_DEPRECATED = function(componentOrHandle) {
88638863
};
88648864
exports.findNodeHandle = findNodeHandle;
88658865
exports.getInspectorDataForInstance = void 0;
8866+
exports.isChildPublicInstance = function () {
8867+
throw Error("isChildPublicInstance() is not available in production.");
8868+
};
88668869
exports.render = function(element, containerTag, callback, concurrentRoot) {
88678870
var root = roots.get(containerTag);
88688871
root ||
@@ -8931,4 +8934,3 @@ if (
89318934
) {
89328935
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
89338936
}
8934-

packages/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js

+56-1
Original file line numberDiff line numberDiff line change
@@ -3676,6 +3676,20 @@ function findCurrentHostFiberImpl(node) {
36763676

36773677
return null;
36783678
}
3679+
function doesFiberContain(parentFiber, childFiber) {
3680+
var node = childFiber;
3681+
var parentFiberAlternate = parentFiber.alternate;
3682+
3683+
while (node !== null) {
3684+
if (node === parentFiber || node === parentFiberAlternate) {
3685+
return true;
3686+
}
3687+
3688+
node = node.return;
3689+
}
3690+
3691+
return false;
3692+
}
36793693

36803694
// Modules provided by RN:
36813695
var emptyObject = {};
@@ -24651,6 +24665,46 @@ function sendAccessibilityEvent(handle, eventType) {
2465124665
}
2465224666
}
2465324667

24668+
function isChildPublicInstance(parentInstance, childInstance) {
24669+
{
24670+
// Paper
24671+
if (
24672+
// $FlowExpectedError[incompatible-type]
24673+
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
24674+
parentInstance._internalFiberInstanceHandleDEV && // $FlowExpectedError[incompatible-type]
24675+
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
24676+
childInstance._internalFiberInstanceHandleDEV
24677+
) {
24678+
return doesFiberContain(
24679+
// $FlowExpectedError[incompatible-call]
24680+
parentInstance._internalFiberInstanceHandleDEV, // $FlowExpectedError[incompatible-call]
24681+
childInstance._internalFiberInstanceHandleDEV
24682+
);
24683+
}
24684+
24685+
var parentInternalInstanceHandle = // $FlowExpectedError[incompatible-call] Type for parentInstance should have been PublicInstance from ReactFiberConfigFabric.
24686+
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
24687+
parentInstance
24688+
);
24689+
var childInternalInstanceHandle = // $FlowExpectedError[incompatible-call] Type for childInstance should have been PublicInstance from ReactFiberConfigFabric.
24690+
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
24691+
childInstance
24692+
); // Fabric
24693+
24694+
if (
24695+
parentInternalInstanceHandle != null &&
24696+
childInternalInstanceHandle != null
24697+
) {
24698+
return doesFiberContain(
24699+
parentInternalInstanceHandle,
24700+
childInternalInstanceHandle
24701+
);
24702+
} // Means that one instance is from Fabric and other is from Paper.
24703+
24704+
return false;
24705+
}
24706+
}
24707+
2465424708
function onRecoverableError(error$1) {
2465524709
// TODO: Expose onRecoverableError option to userspace
2465624710
// eslint-disable-next-line react-internal/no-production-logging, react-internal/warning-args
@@ -24738,6 +24792,7 @@ exports.createPortal = createPortal$1;
2473824792
exports.dispatchCommand = dispatchCommand;
2473924793
exports.findHostInstance_DEPRECATED = findHostInstance_DEPRECATED;
2474024794
exports.findNodeHandle = findNodeHandle;
24795+
exports.isChildPublicInstance = isChildPublicInstance;
2474124796
exports.render = render;
2474224797
exports.sendAccessibilityEvent = sendAccessibilityEvent;
2474324798
exports.unmountComponentAtNode = unmountComponentAtNode;
@@ -24752,6 +24807,6 @@ if (
2475224807
) {
2475324808
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
2475424809
}
24755-
24810+
2475624811
})();
2475724812
}

packages/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js

+3
Original file line numberDiff line numberDiff line change
@@ -8564,6 +8564,9 @@ exports.findHostInstance_DEPRECATED = function(componentOrHandle) {
85648564
};
85658565
exports.findNodeHandle = findNodeHandle;
85668566
exports.getInspectorDataForInstance = void 0;
8567+
exports.isChildPublicInstance = function () {
8568+
throw Error("isChildPublicInstance() is not available in production.");
8569+
};
85678570
exports.render = function(element, containerTag, callback) {
85688571
var root = roots.get(containerTag);
85698572
if (!root) {

packages/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -9040,6 +9040,9 @@ exports.findHostInstance_DEPRECATED = function(componentOrHandle) {
90409040
};
90419041
exports.findNodeHandle = findNodeHandle;
90429042
exports.getInspectorDataForInstance = void 0;
9043+
exports.isChildPublicInstance = function () {
9044+
throw Error("isChildPublicInstance() is not available in production.");
9045+
};
90439046
exports.render = function(element, containerTag, callback) {
90449047
var root = roots.get(containerTag);
90459048
if (!root) {
@@ -9102,4 +9105,3 @@ if (
91029105
) {
91039106
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
91049107
}
9105-

0 commit comments

Comments
 (0)