Repository: microsoft/PowerToys
File: src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/ShellViewModel.cs (C#)

Code before:
        var navigationToken = newCts.Token;

        var command = message.Command.Unsafe;
        if (command is null)
        {
            return;
        }

        var host = _appHostService.GetHostForCommand(message.Context, CurrentPage.ExtensionHost);

        _rootPageService.OnPerformCommand(message.Context, !CurrentPage.IsNested, host);

        try
        {
            if (command is IPage page)
            {
                CoreLogger.LogDebug($"Navigating to page");

                var isMainPage = command == _rootPage;
                _isNested = !isMainPage;

                // Telemetry: Track extension page navigation for session metrics
                if (host is not null)
                {
                    string extensionId = host.GetExtensionDisplayName() ?? "builtin";
                    string commandType = command?.Name ?? command?.Id ?? "unknown";
                    WeakReferenceMessenger.Default.Send<ExtensionInvokedMessage>(
                        new(extensionId, commandType, true, 0));
                }

                // Construct our ViewModel of the appropriate type and pass it the UI Thread context.
                var pageViewModel = _pageViewModelFactory.TryCreatePageViewModel(page, _isNested, host!);
                if (pageViewModel is null)
                {
                    CoreLogger.LogError($"Failed to create ViewModel for page {page.GetType().Name}");
                    throw new NotSupportedException();
                }

                // Clear command bar, ViewModel initialization can already set new commands if it wants to
                OnUIThread(() => WeakReferenceMessenger.Default.Send<UpdateCommandBarMessage>(new(null)));

                // Kick off async loading of our ViewModel
                LoadPageViewModelAsync(pageViewModel, navigationToken)
                    .ContinueWith(
                        (Task t) =>
                        {
                            // clean up the navigation token if it's still ours
                            if (Interlocked.CompareExchange(ref _navigationCts, null, newCts) == newCts)
                            {
                                newCts.Dispose();
                            }

Review comment (suggestion):
It makes more sense to check the `Id` first, since the name is localized and any statistics based on it would be inconsistent.

Code after:

        var navigationToken = newCts.Token;

        var command = message.Command.Unsafe;
        if (command is null)
        {
            return;
        }

        var host = _appHostService.GetHostForCommand(message.Context, CurrentPage.ExtensionHost);

        _rootPageService.OnPerformCommand(message.Context, !CurrentPage.IsNested, host);

        try
        {
            if (command is IPage page)
            {
                CoreLogger.LogDebug($"Navigating to page");

                var isMainPage = command == _rootPage;
                _isNested = !isMainPage;

                // Telemetry: Track extension page navigation for session metrics
                if (host is not null)
                {
                    string extensionId = host.GetExtensionDisplayName() ?? "builtin";
                    string commandId = command?.Id ?? "unknown";
                    string commandName = command?.Name ?? "unknown";
                    WeakReferenceMessenger.Default.Send<TelemetryExtensionInvokedMessage>(
                        new(extensionId, commandId, commandName, true, 0));
                }

                // Construct our ViewModel of the appropriate type and pass it the UI Thread context.
                var pageViewModel = _pageViewModelFactory.TryCreatePageViewModel(page, _isNested, host!);
                if (pageViewModel is null)
                {
                    CoreLogger.LogError($"Failed to create ViewModel for page {page.GetType().Name}");
                    throw new NotSupportedException();
                }

                // Clear command bar, ViewModel initialization can already set new commands if it wants to
                OnUIThread(() => WeakReferenceMessenger.Default.Send<UpdateCommandBarMessage>(new(null)));

                // Kick off async loading of our ViewModel
                LoadPageViewModelAsync(pageViewModel, navigationToken)
                    .ContinueWith(
                        (Task t) =>
                        {
                            // clean up the navigation token if it's still ours
                            if (Interlocked.CompareExchange(ref _navigationCts, null, newCts) == newCts)
                            {