diff --git a/packages/devtools_app/lib/src/screens/inspector_v2/inspector_controller.dart b/packages/devtools_app/lib/src/screens/inspector_v2/inspector_controller.dart index 79827334047..13b43c5ea3b 100644 --- a/packages/devtools_app/lib/src/screens/inspector_v2/inspector_controller.dart +++ b/packages/devtools_app/lib/src/screens/inspector_v2/inspector_controller.dart @@ -462,6 +462,7 @@ class InspectorController extends DisposableController } if ((_receivedFlutterNavigationEvent || _receivedIsolateReloadEvent) && extensionEventKind == 'Flutter.Frame') { + _refreshingAfterNavigationEvent = _receivedFlutterNavigationEvent; _receivedFlutterNavigationEvent = false; _receivedIsolateReloadEvent = false; await refreshInspector(); @@ -519,6 +520,8 @@ class InspectorController extends DisposableController } } + var _refreshingAfterNavigationEvent = false; + RemoteDiagnosticsNode? _determineNewSelection( RemoteDiagnosticsNode? previousSelection, ) { @@ -536,6 +539,17 @@ class InspectorController extends DisposableController ) = _findClosestUnchangedAncestor(previousSelection); if (closestUnchangedAncestor == null) return inspectorTree.root?.diagnostic; + // TODO(elliette): This might cause a race event that will set this to false + // for a subsequent navigate event. Consider passing the value of + // _refreshingAfterNavigationEvent through the method chain from where the + // navigation event is detected. This would require updating the interface + // of InspectorServiceClient.onForceRefresh, or refactoring to avoid doing + // so. + if (_refreshingAfterNavigationEvent) { + _refreshingAfterNavigationEvent = false; + return closestUnchangedAncestor; + } + const distanceOffset = 3; final matchingDescendant = _findMatchingDescendant( of: closestUnchangedAncestor,