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

Code before:
                // Extensions based on Command Palette SDK < 0.3 CommandItem class won't notify when Title changes because Command
                // or Command.Name change. This is a workaround to ensure that the Title is always up-to-date for extensions with old SDK.
                _itemTitle = model.Title;
                _titleCache.Invalidate();
                UpdateProperty(nameof(Title), nameof(Name));

                _defaultCommandContextItemViewModel?.UpdateTitle(model.Command.Name);
                break;

            case nameof(Command.Icon):
                UpdateDefaultContextItemIcon();
                UpdateProperty(nameof(Icon));
                break;
        }
    }

    private void UpdateDefaultContextItemIcon()
    {
        // Command icon takes precedence over our icon on the primary command
        _defaultCommandContextItemViewModel?.UpdateIcon(Command.Icon.IsSet ? Command.Icon : _icon);
    }

    private void UpdateTitle(string? title)
    {
        _itemTitle = title ?? string.Empty;
        _titleCache.Invalidate();
        UpdateProperty(nameof(Title));
    }

    private void UpdateIcon(IIconInfo? iconInfo)
    {
        _icon = new(iconInfo);
        _icon.InitializeProperties();
        UpdateProperty(nameof(Icon));
    }

    private void UpdateDataPackage(IDictionary<string, object?>? properties)
    {
        DataPackage =
            properties?.TryGetValue(WellKnownExtensionAttributes.DataPackage, out var dataPackageView) == true &&
            dataPackageView is DataPackageView view
                ? view
                : null;
        UpdateProperty(nameof(DataPackage));
    }

    public FuzzyTarget GetTitleTarget(IPrecomputedFuzzyMatcher matcher)
        => _titleCache.GetOrUpdate(matcher, Title);

    public FuzzyTarget GetSubtitleTarget(IPrecomputedFuzzyMatcher matcher)
        => _subtitleCache.GetOrUpdate(matcher, Subtitle);

Review comment (security):
[nit] In the long run, it might be cleaner not to coalesce the null here and instead make `_contextMenuFactory` a required injection for the class. That means that the static Instance can be dropped altogether, so the source of truth is not diluted.

Code after:
            dataPackageView is DataPackageView view
                ? view
                : null;
        UpdateProperty(nameof(DataPackage));
    }

    public FuzzyTarget GetTitleTarget(IPrecomputedFuzzyMatcher matcher)
        => _titleCache.GetOrUpdate(matcher, Title);

    public FuzzyTarget GetSubtitleTarget(IPrecomputedFuzzyMatcher matcher)
        => _subtitleCache.GetOrUpdate(matcher, Subtitle);

    /// <remarks>
    /// * Does call SlowInitializeProperties on the created items.
    /// * does NOT call UpdateProperty ; caller must do that.
    /// </remarks>
    private void BuildAndInitMoreCommands()
    {
        var model = _commandItemModel.Unsafe;
        if (model is null)
        {
            return;
        }

        var more = model.MoreCommands;
        var factory = _contextMenuFactory ?? DefaultContextMenuFactory.Instance;
        var results = factory.UnsafeBuildAndInitMoreCommands(more, this);

        List<IContextItemViewModel>? freedItems;
        lock (MoreCommands)
        {
            ListHelpers.InPlaceUpdateList(MoreCommands, results, out freedItems);
        }

        freedItems.OfType<CommandContextItemViewModel>()
                  .ToList()
                  .ForEach(c => c.SafeCleanup());
    }

    protected override void UnsafeCleanup()
    {
        base.UnsafeCleanup();

        lock (MoreCommands)
        {
            MoreCommands.OfType<CommandContextItemViewModel>()
                        .ToList()
                        .ForEach(c => c.SafeCleanup());
            MoreCommands.Clear();
        }