Skip to content

Commit

Permalink
fix: patch public renderer implementations to include isChildPublicIn…
Browse files Browse the repository at this point in the history
…stance (#42249)

Summary:
Pull Request resolved: #42249

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.

Reviewed By: sammy-SC

Differential Revision: D52697885

fbshipit-source-id: c62af6e89e8da3ee6f6c7264bacf6e96030e9db8
  • Loading branch information
hoxyq authored and facebook-github-bot committed Jan 15, 2024
1 parent c393f7a commit c989f63
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3388,6 +3388,20 @@ function findCurrentHostFiberImpl(node) {

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;
}

/**
* In the future, we should cleanup callbacks by cancelling them instead of
Expand Down Expand Up @@ -24331,6 +24345,46 @@ function sendAccessibilityEvent(handle, eventType) {
}
}

function isChildPublicInstance(parentInstance, childInstance) {
{
// Paper
if (
// $FlowExpectedError[incompatible-type]
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
parentInstance._internalFiberInstanceHandleDEV && // $FlowExpectedError[incompatible-type]
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
childInstance._internalFiberInstanceHandleDEV
) {
return doesFiberContain(
// $FlowExpectedError[incompatible-call]
parentInstance._internalFiberInstanceHandleDEV, // $FlowExpectedError[incompatible-call]
childInstance._internalFiberInstanceHandleDEV
);
}

var parentInternalInstanceHandle = // $FlowExpectedError[incompatible-call] Type for parentInstance should have been PublicInstance from ReactFiberConfigFabric.
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
parentInstance
);
var childInternalInstanceHandle = // $FlowExpectedError[incompatible-call] Type for childInstance should have been PublicInstance from ReactFiberConfigFabric.
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
childInstance
); // Fabric

if (
parentInternalInstanceHandle != null &&
childInternalInstanceHandle != null
) {
return doesFiberContain(
parentInternalInstanceHandle,
childInternalInstanceHandle
);
} // Means that one instance is from Fabric and other is from Paper.

return false;
}
}

function onRecoverableError(error$1) {
// TODO: Expose onRecoverableError option to userspace
// eslint-disable-next-line react-internal/no-production-logging, react-internal/warning-args
Expand Down Expand Up @@ -24401,6 +24455,7 @@ exports.createPortal = createPortal$1;
exports.dispatchCommand = dispatchCommand;
exports.findHostInstance_DEPRECATED = findHostInstance_DEPRECATED;
exports.findNodeHandle = findNodeHandle;
exports.isChildPublicInstance = isChildPublicInstance;
exports.render = render;
exports.sendAccessibilityEvent = sendAccessibilityEvent;
exports.stopSurface = stopSurface;
Expand All @@ -24414,6 +24469,6 @@ if (
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
}

})();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8386,6 +8386,9 @@ exports.findHostInstance_DEPRECATED = function(componentOrHandle) {
};
exports.findNodeHandle = findNodeHandle;
exports.getInspectorDataForInstance = void 0;
exports.isChildPublicInstance = function () {
throw Error("isChildPublicInstance() is not available in production.");
};
exports.render = function(element, containerTag, callback, concurrentRoot) {
var root = roots.get(containerTag);
root ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8863,6 +8863,9 @@ exports.findHostInstance_DEPRECATED = function(componentOrHandle) {
};
exports.findNodeHandle = findNodeHandle;
exports.getInspectorDataForInstance = void 0;
exports.isChildPublicInstance = function () {
throw Error("isChildPublicInstance() is not available in production.");
};
exports.render = function(element, containerTag, callback, concurrentRoot) {
var root = roots.get(containerTag);
root ||
Expand Down Expand Up @@ -8931,4 +8934,3 @@ if (
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
}

Original file line number Diff line number Diff line change
Expand Up @@ -3676,6 +3676,20 @@ function findCurrentHostFiberImpl(node) {

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 = {};
Expand Down Expand Up @@ -24651,6 +24665,46 @@ function sendAccessibilityEvent(handle, eventType) {
}
}

function isChildPublicInstance(parentInstance, childInstance) {
{
// Paper
if (
// $FlowExpectedError[incompatible-type]
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
parentInstance._internalFiberInstanceHandleDEV && // $FlowExpectedError[incompatible-type]
// $FlowExpectedError[prop-missing] Don't check via `instanceof ReactNativeFiberHostComponent`, so it won't be leaked to Fabric.
childInstance._internalFiberInstanceHandleDEV
) {
return doesFiberContain(
// $FlowExpectedError[incompatible-call]
parentInstance._internalFiberInstanceHandleDEV, // $FlowExpectedError[incompatible-call]
childInstance._internalFiberInstanceHandleDEV
);
}

var parentInternalInstanceHandle = // $FlowExpectedError[incompatible-call] Type for parentInstance should have been PublicInstance from ReactFiberConfigFabric.
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
parentInstance
);
var childInternalInstanceHandle = // $FlowExpectedError[incompatible-call] Type for childInstance should have been PublicInstance from ReactFiberConfigFabric.
ReactNativePrivateInterface.getInternalInstanceHandleFromPublicInstance(
childInstance
); // Fabric

if (
parentInternalInstanceHandle != null &&
childInternalInstanceHandle != null
) {
return doesFiberContain(
parentInternalInstanceHandle,
childInternalInstanceHandle
);
} // Means that one instance is from Fabric and other is from Paper.

return false;
}
}

function onRecoverableError(error$1) {
// TODO: Expose onRecoverableError option to userspace
// eslint-disable-next-line react-internal/no-production-logging, react-internal/warning-args
Expand Down Expand Up @@ -24738,6 +24792,7 @@ exports.createPortal = createPortal$1;
exports.dispatchCommand = dispatchCommand;
exports.findHostInstance_DEPRECATED = findHostInstance_DEPRECATED;
exports.findNodeHandle = findNodeHandle;
exports.isChildPublicInstance = isChildPublicInstance;
exports.render = render;
exports.sendAccessibilityEvent = sendAccessibilityEvent;
exports.unmountComponentAtNode = unmountComponentAtNode;
Expand All @@ -24752,6 +24807,6 @@ if (
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
}

})();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8564,6 +8564,9 @@ exports.findHostInstance_DEPRECATED = function(componentOrHandle) {
};
exports.findNodeHandle = findNodeHandle;
exports.getInspectorDataForInstance = void 0;
exports.isChildPublicInstance = function () {
throw Error("isChildPublicInstance() is not available in production.");
};
exports.render = function(element, containerTag, callback) {
var root = roots.get(containerTag);
if (!root) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9040,6 +9040,9 @@ exports.findHostInstance_DEPRECATED = function(componentOrHandle) {
};
exports.findNodeHandle = findNodeHandle;
exports.getInspectorDataForInstance = void 0;
exports.isChildPublicInstance = function () {
throw Error("isChildPublicInstance() is not available in production.");
};
exports.render = function(element, containerTag, callback) {
var root = roots.get(containerTag);
if (!root) {
Expand Down Expand Up @@ -9102,4 +9105,3 @@ if (
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
}

0 comments on commit c989f63

Please sign in to comment.