From ba8a14ff84601840887d38168d48d4313a2815d1 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:15:39 -0800 Subject: [PATCH] [Inspector V2] Change selected node heuristic after navigation event triggering a tree refresh (#8645) --- .../screens/inspector_v2/inspector_controller.dart | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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,