Skip to content

Commit 6072e52

Browse files
committed
Simplify getNearestMountedDOMNode to just walk to path and check the map
We don't need the dependency on findFiberByHostInstance now that we maintain our own map of public instances. This relies on the assumption that this is a DOM renderer but we could always add support for more renderer types that need conflict resolution if they happen.
1 parent 2ec16d4 commit 6072e52

File tree

1 file changed

+5
-16
lines changed
  • packages/react-devtools-shared/src/backend/fiber

1 file changed

+5
-16
lines changed

packages/react-devtools-shared/src/backend/fiber/renderer.js

+5-16
Original file line numberDiff line numberDiff line change
@@ -3725,23 +3725,12 @@ export function attach(
37253725
}
37263726

37273727
function getNearestMountedDOMNode(publicInstance: Element): null | Element {
3728-
// TODO: Remove dependency on findFiberByHostInstance.
3729-
const mountedFiber = renderer.findFiberByHostInstance(publicInstance);
3730-
if (mountedFiber != null) {
3731-
if (mountedFiber.stateNode !== publicInstance) {
3732-
// If it's not a perfect match the specific one might be a resource.
3733-
// We don't need to look at any parents because host resources don't have
3734-
// children so it won't be in any parent if it's not this one.
3735-
if (publicInstanceToDevToolsInstanceMap.has(publicInstance)) {
3736-
return publicInstance;
3737-
}
3738-
}
3739-
return mountedFiber.stateNode;
3728+
let domNode: null | Element = publicInstance;
3729+
while (domNode && !publicInstanceToDevToolsInstanceMap.has(domNode)) {
3730+
// $FlowFixMe: In practice this is either null or Element.
3731+
domNode = domNode.parentNode;
37403732
}
3741-
if (publicInstanceToDevToolsInstanceMap.has(publicInstance)) {
3742-
return publicInstance;
3743-
}
3744-
return null;
3733+
return domNode;
37453734
}
37463735

37473736
function getElementIDForHostInstance(

0 commit comments

Comments
 (0)