Skip to content

Commit

Permalink
Remove extra loop (?) (#11889)
Browse files Browse the repository at this point in the history
* Remove extra loop (?)

* prettier
  • Loading branch information
jquense authored and gaearon committed Jan 5, 2018
1 parent ce40f4e commit 1c7c38c
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions packages/react-dom/src/client/ReactDOMComponentTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ export function getClosestInstanceFromNode(node) {
return node[internalInstanceKey];
}

// Walk up the tree until we find an ancestor whose instance we have cached.
let parents = [];
while (!node[internalInstanceKey]) {
parents.push(node);
if (node.parentNode) {
node = node.parentNode;
} else {
Expand All @@ -40,17 +37,13 @@ export function getClosestInstanceFromNode(node) {
}
}

let closest;
let inst = node[internalInstanceKey];
if (inst.tag === HostComponent || inst.tag === HostText) {
// In Fiber, this will always be the deepest root.
return inst;
}
for (; node && (inst = node[internalInstanceKey]); node = parents.pop()) {
closest = inst;
}

return closest;
return null;
}

/**
Expand Down

0 comments on commit 1c7c38c

Please sign in to comment.