From e047eed2eb5b8bb144dd29fbf31b1367de4282d1 Mon Sep 17 00:00:00 2001 From: Tianyu Yao Date: Thu, 17 Nov 2022 11:36:33 -0800 Subject: [PATCH] Fix inspecting for non-fabric Summary: Changelog: [Internal] I think this started to break when https://github.com/facebook/react/pull/25441 was synced to RN. Before, `closestInstance` would only be non-null under Fabric, after it could be non-null in both. And we were using `closestInstance` to determine which data to send to `selectNode` in devtools. This diff makes a change to call `selectNode` once for non-fabric and once for fabric, one of them would not send anything to devtools frontend, this would make sure it works for both platforms. Reviewed By: mondaychen Differential Revision: D41366466 fbshipit-source-id: fcf30d03e443f6fa067782cd31b7cfd2e0cd841e --- Libraries/Inspector/DevtoolsOverlay.js | 6 +++--- Libraries/Inspector/Inspector.js | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Libraries/Inspector/DevtoolsOverlay.js b/Libraries/Inspector/DevtoolsOverlay.js index 5cf03d3de0e98d..f7f391869fde4b 100644 --- a/Libraries/Inspector/DevtoolsOverlay.js +++ b/Libraries/Inspector/DevtoolsOverlay.js @@ -125,11 +125,11 @@ export default function DevtoolsOverlay({ getInspectorDataForViewAtPoint(inspectedView, x, y, viewData => { const {touchedViewTag, closestInstance, frame} = viewData; if (closestInstance != null || touchedViewTag != null) { + // We call `selectNode` for both non-fabric(viewTag) and fabric(instance), + // this makes sure it works for both architectures. + agent.selectNode(findNodeHandle(touchedViewTag)); if (closestInstance != null) { - // Fabric agent.selectNode(closestInstance); - } else { - agent.selectNode(findNodeHandle(touchedViewTag)); } setInspected({ frame, diff --git a/Libraries/Inspector/Inspector.js b/Libraries/Inspector/Inspector.js index d660528e938a26..dcde8ec513be7b 100644 --- a/Libraries/Inspector/Inspector.js +++ b/Libraries/Inspector/Inspector.js @@ -142,12 +142,11 @@ class Inspector extends React.Component< // Sync the touched view with React DevTools. // Note: This is Paper only. To support Fabric, // DevTools needs to be updated to not rely on view tags. - if (this.state.devtoolsAgent) { + const agent = this.state.devtoolsAgent; + if (agent) { + agent.selectNode(findNodeHandle(touchedViewTag)); if (closestInstance != null) { - // Fabric - this.state.devtoolsAgent.selectNode(closestInstance); - } else if (touchedViewTag != null) { - this.state.devtoolsAgent.selectNode(findNodeHandle(touchedViewTag)); + agent.selectNode(closestInstance); } }