From fad09b23c6721cb4329a1fda04fe8fdb22f70b56 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:11:45 -0800 Subject: [PATCH 1/2] After navigation event, select closest unchanged ancestor --- .../src/screens/inspector_v2/inspector_controller.dart | 8 ++++++++ 1 file changed, 8 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..7abbb73fa28 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,11 @@ class InspectorController extends DisposableController ) = _findClosestUnchangedAncestor(previousSelection); if (closestUnchangedAncestor == null) return inspectorTree.root?.diagnostic; + if (_refreshingAfterNavigationEvent) { + _refreshingAfterNavigationEvent = false; + return closestUnchangedAncestor; + } + const distanceOffset = 3; final matchingDescendant = _findMatchingDescendant( of: closestUnchangedAncestor, From b1ca6ef8cbf20c2c9c55a34c8c51d599d8b45c21 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Thu, 19 Dec 2024 13:33:40 -0800 Subject: [PATCH 2/2] Add a TODO and comment. --- .../lib/src/screens/inspector_v2/inspector_controller.dart | 6 ++++++ 1 file changed, 6 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 7abbb73fa28..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 @@ -539,6 +539,12 @@ 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;