From e104b6fe806c1c3c31ce581f18bfa1054ba26a78 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 11 Apr 2024 04:32:54 -0700 Subject: [PATCH] Fix NPE in ui-debugger when child isn't found Summary: Fixes exception that happens occasionally on iOS {F1484099525} triggered here: https://www.internalfb.com/code/fbsource/[033ecc866dfb]/xplat/sonar/desktop/plugins/public/ui-debugger/components/visualizer/Visualization2D.tsx?lines=558 Working theory: activeChildIndex is out of bounds. Added error attribution to make sure it ends up in logview Reviewed By: antonk52 Differential Revision: D56011805 fbshipit-source-id: f511ff7dd22588d301427913d250fdd6cdd558ad --- .../components/visualizer/Visualization2D.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/desktop/plugins/public/ui-debugger/components/visualizer/Visualization2D.tsx b/desktop/plugins/public/ui-debugger/components/visualizer/Visualization2D.tsx index ad5a7891320..d41972e8653 100644 --- a/desktop/plugins/public/ui-debugger/components/visualizer/Visualization2D.tsx +++ b/desktop/plugins/public/ui-debugger/components/visualizer/Visualization2D.tsx @@ -562,7 +562,14 @@ function hitTest(node: NestedNode, mouseCoordinate: Coordinate): NestedNode[] { let children = node.children; if (node.activeChildIdx != null) { - children = [node.children[node.activeChildIdx]]; + const activeChild = node.children[node.activeChildIdx]; + if (activeChild == null) { + console.error( + `[ui-debugger] activeChildIdx not found for ${node.name}: ${node.activeChildIdx} not within ${node.children.length}`, + ); + } else { + children = [activeChild]; + } } const offsetMouseCoord = offsetCoordinate(mouseCoordinate, nodeBounds); let anyChildHitRecursive = false;