Prevent stack overflow in cyclical graphs
Summary: Logview reported "Error: Maximum call stack size exceeded" for "getElementLeaves". Apparently, there was a cycle in the graph that caused it. The new implementation should ignore cycles. Reviewed By: lblasa Differential Revision: D43976359 fbshipit-source-id: bb5218a3b29706146501241492ee079773d5abc3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3d70020f40
commit
ccba2fb73e
@@ -341,20 +341,29 @@ export default class Inspector extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getElementLeaves(tree: ElementSelectorNode): Array<ElementID> {
|
getElementLeaves(tree: ElementSelectorNode): Array<ElementID> {
|
||||||
return tree
|
if (!tree) {
|
||||||
? Object.entries(tree).reduce(
|
return [];
|
||||||
(
|
}
|
||||||
currLeafNode: Array<ElementID>,
|
const leavesSet = new Set<ElementID>();
|
||||||
[id, children]: [ElementID, ElementSelectorNode],
|
|
||||||
): Array<ElementID> =>
|
const treeIteratorStack: [ElementID, ElementSelectorNode][] = [
|
||||||
currLeafNode.concat(
|
...Object.entries(tree),
|
||||||
Object.keys(children).length > 0
|
];
|
||||||
? this.getElementLeaves(children)
|
while (treeIteratorStack.length) {
|
||||||
: [id],
|
const [id, children] = treeIteratorStack.pop()!;
|
||||||
),
|
|
||||||
[],
|
if (leavesSet.has(id)) {
|
||||||
)
|
continue;
|
||||||
: [];
|
}
|
||||||
|
|
||||||
|
if (Object.keys(children).length) {
|
||||||
|
treeIteratorStack.push(...Object.entries(children));
|
||||||
|
} else {
|
||||||
|
leavesSet.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...leavesSet];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return path from given tree structure and id if id is not null; otherwise return any path
|
/// Return path from given tree structure and id if id is not null; otherwise return any path
|
||||||
|
|||||||
Reference in New Issue
Block a user