Skip to content

Commit

Permalink
Simplify getNearestMountedDOMNode to just walk to path and check the map
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sebmarkbage committed Aug 28, 2024
1 parent 2ec16d4 commit 35cfe8f
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions packages/react-devtools-shared/src/backend/fiber/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3725,23 +3725,11 @@ export function attach(
}

function getNearestMountedDOMNode(publicInstance: Element): null | Element {
// TODO: Remove dependency on findFiberByHostInstance.
const mountedFiber = renderer.findFiberByHostInstance(publicInstance);
if (mountedFiber != null) {
if (mountedFiber.stateNode !== publicInstance) {
// If it's not a perfect match the specific one might be a resource.
// We don't need to look at any parents because host resources don't have
// children so it won't be in any parent if it's not this one.
if (publicInstanceToDevToolsInstanceMap.has(publicInstance)) {
return publicInstance;
}
}
return mountedFiber.stateNode;
const domNode: null | Element = publicInstance;
while (domNode && !publicInstanceToDevToolsInstanceMap.has(domNode)) {
domNode = domNode.parentNode;

Check failure on line 3730 in packages/react-devtools-shared/src/backend/fiber/renderer.js

View workflow job for this annotation

GitHub Actions / Run eslint

'domNode' is constant
}
if (publicInstanceToDevToolsInstanceMap.has(publicInstance)) {
return publicInstance;
}
return null;
return domNode;
}

function getElementIDForHostInstance(
Expand Down

0 comments on commit 35cfe8f

Please sign in to comment.