Skip to content

Commit

Permalink
Fix inspecting for non-fabric
Browse files Browse the repository at this point in the history
Summary:
Changelog: [Internal]

I think this started to break when facebook/react#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
  • Loading branch information
tyao1 authored and facebook-github-bot committed Nov 17, 2022
1 parent 3681df2 commit e047eed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Libraries/Inspector/DevtoolsOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions Libraries/Inspector/Inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

1 comment on commit e047eed

@harry170305

This comment was marked as off-topic.

Please sign in to comment.