Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Inspector V2] Change selected node heuristic after navigation event triggering a tree refresh #8645

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ class InspectorController extends DisposableController
}
if ((_receivedFlutterNavigationEvent || _receivedIsolateReloadEvent) &&
extensionEventKind == 'Flutter.Frame') {
_refreshingAfterNavigationEvent = _receivedFlutterNavigationEvent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could there be a race where this is set again (after receiving another event here) before we reach the if statement you added below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it could. I don't think it's likely and the consequence would just be we would then walk down the tree to find the closest matching, so it's not the worst outcome. However, I've added a TODO (below). I initially was passing the value for "refreshingAfterNavigationEvent" down the call chain, but realized that would involve changing the interface to onForceRefresh for the InspectorServiceClient which I didn't want to do:

_receivedFlutterNavigationEvent = false;
_receivedIsolateReloadEvent = false;
await refreshInspector();
Expand Down Expand Up @@ -519,6 +520,8 @@ class InspectorController extends DisposableController
}
}

var _refreshingAfterNavigationEvent = false;

RemoteDiagnosticsNode? _determineNewSelection(
RemoteDiagnosticsNode? previousSelection,
) {
Expand All @@ -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,
Expand Down
Loading