Repository navigation
[trimming] Remap Controls mappers lazily on first handler attachment - #40728
Conversation
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Expert Review — 3 findings · ⚠️ 2 breaking changes
Reviewed commit 9865e80.
Warning
Existing apps would look or behave differently without opting in. See the Behavioral Change Disclosure findings at:
See inline comments for details.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
Active mapper issues can cause stack overflows when wrapping inherited entries on unsealed children and bypass later remaps when inherited delegates are cached, affecting both property and command mappers.
2 open issues
What changed in this PR
This layer prepares .NET MAUI for trimmable handlers by moving Controls mapper remaps from startup to first handler attachment. Default dependency-injection handler registrations remain unchanged.
Changes:
- Adds base-first, execute-once remapping hooks and removes eager startup remapping.
- Separates framework mappings from application customizations and preserves app-installed platform view factories.
- Adds mapper, attachment, concurrency and factory tests, plus migration guidance.
| File | Description |
|---|---|
src/Core/tests/UnitTests/PropertyMapperExtensionTests.cs |
Tests property customization preservation and cached mappings. |
src/Core/tests/UnitTests/OneTimeInitializationActionTests.cs |
Tests execute-once and concurrent waiting behavior. |
src/Core/tests/UnitTests/CommandMapperExtensionTests.cs |
Tests command customization preservation. |
src/Core/src/PropertyMapperExtensions.cs |
Separates app customizations from Controls remaps. |
src/Core/src/PropertyMapper.cs |
Adds framework cells, customization records and versioned caches. |
src/Core/src/MappingCustomizationSequence.cs |
Orders customizations across mappers. |
src/Core/src/Handlers/Window/WindowHandler.cs |
Seals built-in Window mappings. |
src/Core/src/Handlers/WebView/WebViewHandler.cs |
Seals built-in WebView mappings. |
src/Core/src/Handlers/View/ViewHandler.cs |
Seals shared view property and command mappings. |
src/Core/src/Handlers/Toolbar/ToolbarHandler.cs |
Seals built-in Toolbar mappings. |
src/Core/src/Handlers/TimePicker/TimePickerHandler.cs |
Seals built-in TimePicker mappings. |
src/Core/src/Handlers/TabbedView/TabbedViewHandler.cs |
Seals the TabbedView mapper. |
src/Core/src/Handlers/SwipeView/SwipeViewHandler.cs |
Seals built-in SwipeView mappings. |
src/Core/src/Handlers/Stepper/StepperHandler.cs |
Seals built-in Stepper mappings. |
src/Core/src/Handlers/Slider/SliderHandler.cs |
Seals built-in Slider mappings. |
src/Core/src/Handlers/ShapeView/ShapeViewHandler.cs |
Seals built-in shape mappings. |
src/Core/src/Handlers/SearchBar/SearchBarHandler2.Android.cs |
Seals Material3 SearchBar property mappings. |
src/Core/src/Handlers/SearchBar/SearchBarHandler.cs |
Seals SearchBar property and command mappings. |
src/Core/src/Handlers/ScrollView/ScrollViewHandler.cs |
Seals built-in ScrollView mappings. |
src/Core/src/Handlers/RefreshView/RefreshViewHandler.cs |
Seals built-in RefreshView mappings. |
src/Core/src/Handlers/RadioButton/RadioButtonHandler.cs |
Seals built-in RadioButton mappings. |
src/Core/src/Handlers/Picker/PickerHandler.cs |
Seals built-in Picker mappings. |
src/Core/src/Handlers/Page/PageHandler.cs |
Seals built-in Page mappings. |
src/Core/src/Handlers/NavigationPage/NavigationViewHandler.cs |
Seals the navigation mapper. |
src/Core/src/Handlers/Label/LabelHandler.cs |
Seals built-in Label mappings. |
src/Core/src/Handlers/ImageButton/ImageButtonHandler.cs |
Seals built-in ImageButton mappings. |
src/Core/src/Handlers/FlyoutView/FlyoutViewHandler.cs |
Seals built-in FlyoutView mappings. |
src/Core/src/Handlers/Entry/EntryHandler2.Android.cs |
Seals Material3 Entry property and command mappings. |
src/Core/src/Handlers/Entry/EntryHandler.cs |
Seals Entry property and command mappings. |
src/Core/src/Handlers/Element/RemappingHelper.cs |
Removes the global remapping helper. |
src/Core/src/Handlers/Element/OneTimeInitializationAction.cs |
Adds blocking, execute-once initialization. |
src/Core/src/Handlers/Element/IControlsMapperRemappable.cs |
Defines the internal remapping contract. |
src/Core/src/Handlers/Element/ElementHandler.cs |
Remaps before native creation and initial mapping. |
src/Core/src/Handlers/Editor/EditorHandler2.Android.cs |
Seals Material3 Editor property and command mappings. |
src/Core/src/Handlers/Editor/EditorHandler.cs |
Seals Editor property and command mappings. |
src/Core/src/Handlers/DatePicker/DatePickerHandler.cs |
Seals built-in DatePicker mappings. |
src/Core/src/Handlers/ContentButton/ContentButtonHandler.cs |
Seals built-in ContentButton mappings. |
src/Core/src/Handlers/CheckBox/CheckBoxHandler.cs |
Seals built-in CheckBox mappings. |
src/Core/src/Handlers/Button/ButtonHandler.cs |
Seals the main Button mapper. |
src/Core/src/Handlers/Application/ApplicationHandler.cs |
Seals built-in Application mappings. |
src/Core/src/CommandMapperExtensions.cs |
Adds customization-aware command remap helpers. |
src/Core/src/CommandMapper.cs |
Adds framework cells and sequenced command compositions. |
src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPagePlatformViewFactoryTests.cs |
Tests factory installation and app-factory preservation. |
src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.Android.cs |
Tests templated RadioButton factories and app overrides. |
src/Controls/tests/DeviceTests/ControlsDeviceTestExtensions.cs |
Removes eager remapping from test setup. |
src/Controls/tests/Core.UnitTests/VisualElementTests.cs |
Tests container-view notifications after remapping. |
src/Controls/tests/Core.UnitTests/VisualElementMapperTests.cs |
Initializes remaps before inspecting global mapper keys. |
src/Controls/tests/Core.UnitTests/ElementTests.cs |
Tests remapping before non-ElementHandler attachment. |
src/Controls/tests/Core.UnitTests/CommandSourceTests.cs |
Checks command dependencies before handler attachment. |
src/Controls/tests/Core.UnitTests/Animations/StoryboardTests.cs |
Restores customization records and caches after testing. |
src/Controls/src/Core/Window/Window.Mapper.cs |
Makes Window remaps lazy and customization-aware. |
src/Controls/src/Core/WebView/WebView.Mapper.cs |
Defers WebView platform-specific remaps. |
src/Controls/src/Core/VisualElement/VisualElement.Mapper.cs |
Defers shared visual property and focus remaps. |
src/Controls/src/Core/Toolbar/Toolbar.Mapper.cs |
Implements lazy remapping for non-Element toolbars. |
src/Controls/src/Core/TimePicker/TimePicker.Mapper.cs |
Defers TimePicker platform-specific remapping. |
src/Controls/src/Core/TabbedPage/TabbedPage.Mapper.cs |
Defers remaps and preserves app-installed factories. |
src/Controls/src/Core/Switch/Switch.Mapper.cs |
Moves Switch remapping to first attachment. |
src/Controls/src/Core/SwipeView/SwipeView.Mapper.cs |
Defers the Controls background append. |
src/Controls/src/Core/Stepper/Stepper.Mapper.cs |
Defers the increment-to-interval mapping. |
src/Controls/src/Core/Slider/Slider.Mapper.cs |
Defers Slider platform-specific remapping. |
src/Controls/src/Core/Shape/Shape.Mapper.cs |
Defers stroke-dash remapping. |
src/Controls/src/Core/SearchBar/SearchBar.Mapper.cs |
Defers SearchBar remaps while retaining command dependencies. |
src/Controls/src/Core/ScrollView/ScrollView.Mapper.cs |
Defers ScrollView platform-specific remapping. |
src/Controls/src/Core/RefreshView/RefreshView.Mapper.cs |
Defers remapping while retaining command dependencies. |
src/Controls/src/Core/RadioButton/RadioButton.Mapper.cs |
Defers remaps and preserves Android app factories. |
src/Controls/src/Core/Picker/Picker.Mapper.cs |
Defers item-source and platform-specific remaps. |
src/Controls/src/Core/NavigationPage/NavigationPage.Mapper.cs |
Defers Apple navigation remaps and integration setup. |
src/Controls/src/Core/Layout/Layout.Mapper.cs |
Removes the empty remapping partial. |
src/Controls/src/Core/Label/Label.Mapper.cs |
Defers framework remaps; retains type-initialization public appends. |
src/Controls/src/Core/ImageButton/ImageButton.Mapper.cs |
Defers Android ripple remaps. |
src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs |
Removes eager remapping; retains navigation transition hooks. |
src/Controls/src/Core/FlyoutPage/FlyoutPage.Mapper.cs |
Defers FlyoutPage remaps and Apple integration setup. |
src/Controls/src/Core/Entry/Entry.Mapper.cs |
Defers text, focus and platform-specific remaps. |
src/Controls/src/Core/Element/Element.Mapper.cs |
Implements the base one-time remapping hook. |
src/Controls/src/Core/Element/Element.cs |
Invokes remapping during handler assignment. |
src/Controls/src/Core/Editor/Editor.Mapper.cs |
Defers text, focus and sizing remaps. |
src/Controls/src/Core/DatePicker/DatePicker.Mapper.cs |
Defers DatePicker platform-specific remapping. |
src/Controls/src/Core/ContentPage/ContentPage.Mapper.cs |
Defers keyboard and Apple page remaps. |
src/Controls/src/Core/ContentButton/ContentButton.Mapper.cs |
Defers Android ripple remaps. |
src/Controls/src/Core/CheckBox/CheckBox.Mapper.cs |
Defers color remapping; retains command dependency setup. |
src/Controls/src/Core/Button/Button.Mapper.cs |
Defers text, layout and platform-specific remaps. |
src/Controls/src/Core/Application/Application.Mapper.cs |
Defers Android soft-input remapping. |
docs/design/HandlerResolution.md |
Documents lazy timing, customization semantics and migration. |
Review effort: Balanced
7e6ef48 to
82d74fc
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Custom Android and Windows toolbar handlers that do not derive from ElementHandler miss Controls mappings until a built-in toolbar attaches, requiring a remapping fix and regression coverage.
1 open issue
2 resolved since last review
Review effort: Balanced
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Expert Review — 2 findings · ⚠️ 2 breaking changes
Reviewed commit 82d74fc.
Warning
Existing apps would look or behave differently without opting in. See the Behavioral Change Disclosure findings at:
See inline comments for details.
There was a problem hiding this comment.
Expert Review — 6 findings · ⚠️ 3 breaking changes
Reviewed commit 837a686.
Warning
Existing apps would look or behave differently without opting in. See the Behavioral Change Disclosure findings at:
See inline comments for details.
| - **Inherited mappings of built-in mappers are bound to the mapper they are read from.** `GetProperty` and `GetCommand` on a sealed built-in handler mapper, such as `LabelHandler.Mapper`, return a mapping bound to that mapper for keys inherited from `ViewHandler.ViewMapper`, rather than the `ViewMapper` delegate itself. Invoking or wrapping the returned mapping behaves as before. To check whether a handler mapper still uses the shared `ViewMapper` mapping, compare the behavior rather than the delegates. | ||
| - **Controls remaps run when the first control of each type is attached.** Lazy remapping is what allows an app to trim the handlers and mapper code of controls it never uses, so there is no switch that restores startup remapping. Before the first instance of a Controls type is attached, the global mappers do not contain the keys that type's remap adds, such as the `BackgroundColor`, `BackgroundImageSource` and `SemanticProperties.*` redirects on `ViewHandler.ViewMapper` or `TextType` on `LabelHandler.Mapper`. A custom mapper built by copying `GetKeys()` and `GetProperty()` delegates into an unchained mapper during startup no longer gets those keys, so its handlers ignore changes to those properties. To migrate, chain the custom mapper to the built-in one instead, for example `new PropertyMapper<ILabel, ILabelHandler>(LabelHandler.Mapper) { ... }`, or customize the built-in mapper with `AppendToMapping`, `PrependToMapping`, `ModifyMapping` or `ReplaceMapping`. Chained mappers and recorded customizations observe a remap whenever it runs. If a copy is unavoidable, take it after a control of that type has been attached, for example from its `HandlerChanged` event. | ||
| - **Framework remaps of inherited keys capture the parent's customizations at first attachment.** A remap of a key a handler mapper inherits builds on the parent's mapping as it is when the remap runs. It now also includes app customizations of that key on the parent registered after `UseMauiApp` but before the first control of that type is attached. To have a customization apply to every handler, register it before the first control is attached, for example in `MauiProgram`, or customize the child mapper's key directly. | ||
| - **Platform view factories.** An app factory assigned to `TabbedViewHandler.PlatformViewFactory`, or to `RadioButtonHandler.PlatformViewFactory` on Android, before the first `TabbedPage` or `RadioButton` is attached is kept and replaces the Controls factory, as a factory assigned after `UseMauiApp` did before. Reading the property during startup to wrap the Controls factory now returns `null`, because the Controls factory is installed on first attachment. |
There was a problem hiding this comment.
[major] Behavioral Change Disclosure - After UseMauiApp and before the first TabbedPage attachment, capturing var previous = TabbedViewHandler.PlatformViewFactory and installing handler => previous(handler) previously wrapped the Controls factory and displayed the pages. Now previous is null; the lazy installer preserves the non-null wrapper through ??=, and first attachment throws NullReferenceException. This affects Android, iOS, MacCatalyst and Windows, and the equivalent RadioButton factory wrapper on Android. The startup timing is disclosed, but no compatibility opt-out supplies the previously available Controls factory. Provide an opt-out preserving this working configuration for the stack's main/.NET 12 target.
| - **App customizations registered before a remap now compose on top of it.** Previously, a Controls remap that ran after an app's `AppendToMapping`, `PrependToMapping`, `ModifyMapping`, or `ReplaceMapping`, for example one registered in a handler's static constructor before `UseMauiApp`, wrapped or replaced the app's change. Now the Controls remap is placed underneath the app's change, as it already was for customizations registered after `UseMauiApp`. Callbacks appended to two related keys can therefore run in a different order. For example, with app callbacks appended to `StepperHandler.Mapper`'s `Increment` and `Interval` keys before `UseMauiApp`, changing `Stepper.Increment` used to run the app's `Increment` callback before the Controls redirect to `Interval`, and now runs it after the `Interval` callback. To migrate, don't rely on the order of callbacks across keys. A callback that needs the native state another key's update produces should read it from the virtual view, or update that state itself. | ||
| - **App customizations registered before a remap now compose on top of it.** Previously, a Controls remap that ran after an app's `AppendToMapping`, `PrependToMapping`, `ModifyMapping`, or `ReplaceMapping`, for example one registered in a handler's static constructor before `UseMauiApp`, wrapped or replaced the app's change. Now the Controls remap is placed underneath the app's change, whenever the first control of that type is attached. Callbacks appended to two related keys can therefore run in a different order. For example, with app callbacks appended to `StepperHandler.Mapper`'s `Increment` and `Interval` keys before `UseMauiApp`, changing `Stepper.Increment` used to run the app's `Increment` callback before the Controls redirect to `Interval`, and now runs it after the `Interval` callback. To migrate, don't rely on the order of callbacks across keys. A callback that needs the native state another key's update produces should read it from the virtual view, or update that state itself. | ||
| - **Inherited mappings of built-in mappers are bound to the mapper they are read from.** `GetProperty` and `GetCommand` on a sealed built-in handler mapper, such as `LabelHandler.Mapper`, return a mapping bound to that mapper for keys inherited from `ViewHandler.ViewMapper`, rather than the `ViewMapper` delegate itself. Invoking or wrapping the returned mapping behaves as before. To check whether a handler mapper still uses the shared `ViewMapper` mapping, compare the behavior rather than the delegates. | ||
| - **Controls remaps run when the first control of each type is attached.** Lazy remapping is what allows an app to trim the handlers and mapper code of controls it never uses, so there is no switch that restores startup remapping. Before the first instance of a Controls type is attached, the global mappers do not contain the keys that type's remap adds, such as the `BackgroundColor`, `BackgroundImageSource` and `SemanticProperties.*` redirects on `ViewHandler.ViewMapper` or `TextType` on `LabelHandler.Mapper`. A custom mapper built by copying `GetKeys()` and `GetProperty()` delegates into an unchained mapper during startup no longer gets those keys, so its handlers ignore changes to those properties. To migrate, chain the custom mapper to the built-in one instead, for example `new PropertyMapper<ILabel, ILabelHandler>(LabelHandler.Mapper) { ... }`, or customize the built-in mapper with `AppendToMapping`, `PrependToMapping`, `ModifyMapping` or `ReplaceMapping`. Chained mappers and recorded customizations observe a remap whenever it runs. If a copy is unavoidable, take it after a control of that type has been attached, for example from its `HandlerChanged` event. |
There was a problem hiding this comment.
[major] Behavioral Change Disclosure - After UseMauiApp, before any visual control is created or attached, copy LabelHandler.Mapper.GetKeys() and its GetProperty delegates into an unchained mapper used by a custom LabelHandler. Previously the copy included BackgroundColor, so changing the attached Label's BackgroundColor updated its displayed background. Now that key is absent; attachment remaps only the global mapper, and subsequent BackgroundColor changes leave the displayed background unchanged on Android, iOS, MacCatalyst and Windows. Live captured delegates cannot supply a missing key. The migration guidance discloses this configuration but explicitly provides no compatibility opt-out. For the stack's main/.NET 12 target, provide an opt-out preserving startup remapping; requiring existing applications to rewrite their mapper does not preserve their configuration.
| internal override void RemapForControls() | ||
| { | ||
| base.RemapForControls(); | ||
| s_remappedForControls.InvokeOnce(); |
There was a problem hiding this comment.
[major] Behavioral Change Disclosure - On iOS, MacCatalyst or Windows, append an application callback to ViewHandler.ViewMapper's Background key after UseMauiApp but before the first SwipeView attaches, without customizing that key on SwipeViewHandler.Mapper. Previously the eager SwipeView remap captured the parent before this registration, so that callback did not run for SwipeView background updates. Now the inherited-key remap captures the parent at first attachment, including the callback; subsequent SwipeView Background updates invoke it where they previously invoked none. App code counting calls for SwipeView observes this changed frequency. The docs disclose capture timing, but no compatibility opt-out preserves the previous callback set. Provide an opt-out retaining startup capture behavior for the stack's main/.NET 12 target.
| internal override void RemapForControls() | ||
| { | ||
| base.RemapForControls(); | ||
| s_remappedForControls.InvokeOnce(); |
There was a problem hiding this comment.
[major] Backward Compatibility and Migration - After UseMauiApp and before the first Button attachment, replacing the public ButtonHandler.Mapper field with new PropertyMapper<IButton, IButtonHandler>(ButtonHandler.Mapper) { [nameof(IButton.Text)] = CustomTextMapping } previously preserved the app's text mapping for initial rendering and later Text changes. Now this lazy remap targets the replacement mapper and replaces CustomTextMapping with Controls MapText. The replacement is unsealed: its first local Text assignment is not recorded as an application customization by SetPropertyCore, so ReplaceMappingForControls discards it as framework state. Custom text rendering is lost on Android, iOS, MacCatalyst and Windows even with a chained mapper, not the documented startup copy. Preserve explicit overrides on replacement global mappers and cover this startup configuration.
|
|
||
| VirtualView = view; | ||
|
|
||
| if (VirtualView is IControlsMapperRemappable remappable) |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - No regression test isolates this direct SetVirtualView remap hook. The new Element/Toolbar tests exercise their Handler setters; existing direct-attachment tests use Controls elements whose setters also remap, and their factories do not assert remap state. Removing this hook therefore leaves those assertions satisfied while direct attachment creates the native view before remapping. Add an IControlsMapperRemappable stub with a non-remapping Handler setter and assert remapping has completed inside platform-view creation and the first mapper callback, independently of global initialization order.
| { | ||
| TabbedViewHandler.PlatformViewFactory = null; | ||
|
|
||
| TabbedPage.InstallPlatformViewFactory(); |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - Both new factory suites explicitly call InstallPlatformViewFactory before attaching, so they test the installer and its preservation guard, not lazy first-attachment installation. Deleting the installer call from TabbedPage.RemapForControlsOnce or Android RadioButton.RemapForControlsOnce still satisfies these tests. Existing ordinary attachment tests can also be masked when this suite preinstalls and restores the process-wide factory first. In a fresh app those regressions respectively make TabbedViewHandler.CreatePlatformView throw and create an AppCompatRadioButton instead of the templated content container. Add isolated cold first-attachment tests with null factories and untouched one-time state, without calling either installer first; assert page creation and Android radio template content. Retain the helper tests for factory preservation.
837a686 to
5d5b3a3
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The new factory tests explicitly install factories before attachment, leaving lazy first-attachment behavior untested for TabbedPage’s throwing fallback and templated RadioButton’s incorrect native fallback.
3 open issues
Review effort: Balanced
| #endif | ||
| #if ANDROID | ||
| RadioButtonHandler.PlatformViewFactory = CreatePlatformView; | ||
| InstallPlatformViewFactory(); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Expert Review — 7 findings · ⚠️ 4 breaking changes
Reviewed commit 5d5b3a3.
Warning
Existing apps would look or behave differently without opting in. See the Behavioral Change Disclosure findings at:
See inline comments for details.
Previously reported findings were not duplicated.
| #if PLATFORM | ||
| // This runs lazily on first attachment; keep a factory the app installed during startup, which would | ||
| // have replaced the Controls factory when it was installed eagerly. | ||
| internal static void InstallPlatformViewFactory() => |
There was a problem hiding this comment.
[major] Behavioral Change Disclosure - After UseMauiApp and before the first TabbedPage attachment, an app captures var previous = TabbedViewHandler.PlatformViewFactory and installs handler => previous(handler) to wrap native view creation. Previously previous was the Controls factory and the pages displayed; now previous is null, the lazy installer preserves the non-null wrapper through ??=, and first attachment throws NullReferenceException. This affects Android, iOS, MacCatalyst and Windows, and the equivalent RadioButton factory wrapper on Android. The docs disclose the startup timing change, but there is no compatibility opt-out supplying the previously available Controls factory for the stack's main/.NET 12 target. The new factory tests explicitly initialize the Controls factory before capturing it, so they do not cover this existing startup configuration.
| internal override void RemapForControls() | ||
| { | ||
| base.RemapForControls(); | ||
| s_remappedForControls.InvokeOnce(); |
There was a problem hiding this comment.
[major] Behavioral Change Disclosure - After UseMauiApp and before the first Button attachment, replace the public ButtonHandler.Mapper field with new PropertyMapper<IButton, IButtonHandler>(ButtonHandler.Mapper) { [nameof(IButton.Text)] = CustomTextMapping }, where CustomTextMapping displays an application-specific prefix. Previously that mapping rendered the prefixed text initially and on later Text changes; now first attachment remaps the replacement mapper and substitutes Controls MapText, so the prefix disappears on Android, iOS, MacCatalyst and Windows. There is neither a compatibility opt-out nor a breaking-change callout for this replacement-field configuration on the stack's main/.NET 12 target.
[major] Handler Mapper and Property Patterns - The replacement is unsealed: SetPropertyCore does not record its first local Text assignment as an application customization, so ReplaceMappingForControls replaces it as framework state. Chaining to the built-in mapper does not protect this explicit override. Preserve overrides on replacement global mappers and cover this startup configuration; the existing chained direct-replacement test seals its child mapper and cannot catch it.
| - **App customizations registered before a remap now compose on top of it.** Previously, a Controls remap that ran after an app's `AppendToMapping`, `PrependToMapping`, `ModifyMapping`, or `ReplaceMapping`, for example one registered in a handler's static constructor before `UseMauiApp`, wrapped or replaced the app's change. Now the Controls remap is placed underneath the app's change, whenever the first control of that type is attached. Callbacks appended to two related keys can therefore run in a different order. For example, with app callbacks appended to `StepperHandler.Mapper`'s `Increment` and `Interval` keys before `UseMauiApp`, changing `Stepper.Increment` used to run the app's `Increment` callback before the Controls redirect to `Interval`, and now runs it after the `Interval` callback. To migrate, don't rely on the order of callbacks across keys. A callback that needs the native state another key's update produces should read it from the virtual view, or update that state itself. | ||
| - **Inherited mappings of built-in mappers are bound to the mapper they are read from.** `GetProperty` and `GetCommand` on a sealed built-in handler mapper, such as `LabelHandler.Mapper`, return a mapping bound to that mapper for keys inherited from `ViewHandler.ViewMapper`, rather than the `ViewMapper` delegate itself. Invoking or wrapping the returned mapping behaves as before. To check whether a handler mapper still uses the shared `ViewMapper` mapping, compare the behavior rather than the delegates. | ||
| - **Controls remaps run when the first control of each type is attached.** Lazy remapping is what allows an app to trim the handlers and mapper code of controls it never uses, so there is no switch that restores startup remapping. Before the first instance of a Controls type is attached, the global mappers do not contain the keys that type's remap adds, such as the `BackgroundColor`, `BackgroundImageSource` and `SemanticProperties.*` redirects on `ViewHandler.ViewMapper` or `TextType` on `LabelHandler.Mapper`. A custom mapper built by copying `GetKeys()` and `GetProperty()` delegates into an unchained mapper during startup no longer gets those keys, so its handlers ignore changes to those properties. To migrate, chain the custom mapper to the built-in one instead, for example `new PropertyMapper<ILabel, ILabelHandler>(LabelHandler.Mapper) { ... }`, or customize the built-in mapper with `AppendToMapping`, `PrependToMapping`, `ModifyMapping` or `ReplaceMapping`. Chained mappers and recorded customizations observe a remap whenever it runs. If a copy is unavoidable, take it after a control of that type has been attached, for example from its `HandlerChanged` event. | ||
| - **Framework remaps of inherited keys capture the parent's customizations at first attachment.** A remap of a key a handler mapper inherits builds on the parent's mapping as it is when the remap runs. It now also includes app customizations of that key on the parent registered after `UseMauiApp` but before the first control of that type is attached. To have a customization apply to every handler, register it before the first control is attached, for example in `MauiProgram`, or customize the child mapper's key directly. |
There was a problem hiding this comment.
[major] Behavioral Change Disclosure - On iOS, MacCatalyst or Windows, append an application callback to ViewHandler.ViewMapper's Background key after UseMauiApp but before the first SwipeView attaches, without customizing that key on SwipeViewHandler.Mapper. Previously the eager SwipeView remap captured the parent before this registration, so that callback did not run for SwipeView background updates. Now the inherited-key remap captures the parent at first attachment, including the callback; subsequent SwipeView Background updates invoke it where they previously invoked none. App code counting calls for SwipeView observes this changed frequency. The docs disclose capture timing, but no compatibility opt-out preserves the previous callback set. Provide an opt-out retaining startup capture behavior for the stack's main/.NET 12 target.
|
|
||
| VirtualView = view; | ||
|
|
||
| if (VirtualView is IControlsMapperRemappable remappable) |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - No test isolates this direct SetVirtualView hook or its position before native creation. The new Element and Toolbar tests exercise their Handler setters; existing direct-attachment factory tests do not assert remap state. Removing this hook can therefore leave those assertions satisfied although direct cold attachment creates the native view before its Controls factory/configuration is installed; the later Handler assignment cannot repair that ordering. Add an IControlsMapperRemappable stub with a non-remapping Handler setter and assert remap completion inside platform creation and the first mapper callback, independently of process-wide initialization.
| { | ||
| TabbedViewHandler.PlatformViewFactory = null; | ||
|
|
||
| TabbedPage.InstallPlatformViewFactory(); |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - Both new factory suites explicitly install the Controls factory before attachment. They discriminate the null/non-null preservation guard, but still satisfy their assertions if InstallPlatformViewFactory is removed from TabbedPage.RemapForControlsOnce or Android RadioButton.RemapForControlsOnce. Ordinary attachment tests can also be masked when these tests preinstall and restore the process-wide factory first. In a fresh app, those regressions respectively reach TabbedViewHandler.CreatePlatformView's NotImplementedException on Android/iOS/MacCatalyst/Windows and create an AppCompatRadioButton rather than Android's templated ContentViewGroup. Add isolated cold first-attachment tests with null factories and untouched one-time state, without explicit installer calls; assert page creation and radio template content. Retain these helper-level preservation tests.
| { | ||
| static Label() => RemapForControls(); | ||
| #if ANDROID || IOS || MACCATALYST | ||
| static Label() => AppendControlsMappings(); |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - Restoring the public appends to Label type initialization fixes the reported customization-order regression, but no regression test exercises that order. Existing selection/RTL tests do not register an app append between Label construction and attachment; generic mapper composition tests cannot detect moving this registration back into the lazy remap. On Android, construct the first Label with a single-primary-tap recognizer and no clip/shadow container, append an IsTextSelectable callback setting PlatformView.Focusable=false, attach, then toggle selection true and false. Deferring the Controls append again makes it run last and restore Focusable=true. Cover this scenario and the opposite registration order; also protect the analogous Apple FlowDirection append ordering.
Controls no longer applies its mapper remaps eagerly from UseMauiApp and static constructors. Each remappable Controls type overrides an internal RemapForControls() that calls its base and then runs its own remap once through OneTimeInitializationAction. The Controls Element handler setter and ElementHandler.SetVirtualView (via the internal IControlsMapperRemappable interface) invoke it before the element's properties are first mapped, so the remaps apply regardless of how the handler was registered or created, including compatibility renderers and non-element types such as Toolbar. RemappingHelper and the empty Layout.Mapper.cs are removed, the eager remap list in AppHostBuilderExtensions is dropped (default handler DI registrations and ControlsNavigationTransitionHooks.Install() remain), and the RadioButton/TabbedPage platform view factories keep a factory the app already installed. Update HandlerResolution.md to describe lazy remapping and make tests that read global mapper keys trigger the remap first. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Register Label's public Android IsTextSelectable and Apple FlowDirection appends from its static constructor again, so they are recorded when the Label type is initialized, as before remapping became lazy. An app append registered after the first Label is created keeps running after them. Extract the TabbedPage and Android RadioButton platform view factory installs into InstallPlatformViewFactory and add device tests for the unset-factory and app-factory cases; both fail if the factory is installed with = instead of ??=. Document the behavior changes of lazy remapping with migration guidance. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A custom IToolbarHandler that does not derive from ElementHandler never reached the SetVirtualView remap hook, so a mapper chained to ToolbarHandler.Mapper lacked the Controls mappings until a built-in toolbar handler attached. The Toolbar handler setter now runs the remap before the handler is connected, like the Element handler setter. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
5d5b3a3 to
c103beb
Compare
|
/review expert-review |
This comment has been minimized.
This comment has been minimized.
Selected Tests
🧪 Test selection — click to expand
🧪 UI tests — the full suite on every platform❌ Could not queue GPT-6.2 Sol: Run the full UI suite on all four platforms, including Android Material3, because base mapper initialization moved from startup to first attachment. 🧪 Running — 77 categories on Android, iOS, MacCatalyst, WindowsThe complete 🧪 Device tests —
|
| Platform | Categories |
|---|---|
| Android | Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay |
| iOS | Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay |
| MacCatalyst | Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay |
| Windows | Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay |
⏭️ Skipped — what neither suite runs
Device tests — 3 categories, 0 platforms
Categories not run: Graphics, Essentials, BlazorWebView
Each skipped platform and project is listed as a maui-pr-devicetests (skipped) … status on this commit. Use /azp run maui-pr-devicetests for the full suite.
🤖 Why these tests — AI rationale (GPT-6.2 Sol + MAI Code 2)
UI tests
Each model chose independently; every test that runs was selected by at least one of them.
| Platform | GPT-6.2 Sol | MAI Code 2 |
|---|---|---|
| Android | all categories | all categories |
| iOS | all categories | all categories |
| MacCatalyst | all categories | all categories |
| Windows | all categories | all categories |
GPT-6.2 Sol — Run the full UI suite on all four platforms, including Android Material3, because base mapper initialization moved from startup to first attachment.
- Element, VisualElement and ElementHandler change first-attachment behavior across controls and platforms.
- AppHostBuilderExtensions removes eager remapping; Android Label mapper timing warrants the Material3 lane.
- No UI lane is excluded.
MAI Code 2 — Lazy Controls mapper remapping touches base Element/VisualElement and handler attachment across all platforms; run the full UI suite and all Controls/Core device tests.
- Element/VisualElement handler attachment now triggers mapper remaps, affecting controls broadly rather than one feature.
- Mapper files changed across buttons, inputs, pickers, navigation, pages, toolbar, window, and shared controls on all platforms.
- Core ElementHandler participation and compatibility-renderer attachment make this a wide-blast-radius UI change requiring a full run.
- No UI area or platform is deliberately excluded because the remap timing is framework-wide.
Device tests
Each model chose independently; every test that runs was selected by at least one of them.
| Platform | GPT-6.2 Sol | MAI Code 2 |
|---|---|---|
| Android | Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay |
Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay |
| iOS | Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay |
Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay |
| MacCatalyst | Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay |
Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay |
| Windows | Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay |
Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.Button, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay |
GPT-6.2 Sol — Run all Controls and Core device tests on all four platforms to cover lazy remapping and the new platform-view-factory regressions.
- ElementHandler and Controls startup affect attachment throughout Core and Controls.
- Includes Android RadioButton and cross-platform TabbedPage factory regressions.
- No direct change to Graphics, Essentials or BlazorWebView.
MAI Code 2 — Lazy mapper initialization and handler attachment affect Controls and Core behavior on every device-test platform; run all Controls and Core units.
- Base Element, VisualElement, and Core ElementHandler changes can affect every Controls and Core handler unit.
- Changed Controls mappers span many controls and platform-specific application, rendering, and factory behavior.
- Includes the changed TabbedPage and RadioButton device coverage plus mapper/element lifecycle regressions on all platforms.
- Excludes Graphics, Essentials, and BlazorWebView because those systems are not changed.
Generated by /review run-tests. A targeted run is a fast signal, not full-suite certification.
<!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `cdeafb72937dc746d00866464afe6553904c7d9f` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 7/10 | ↑ Two review rounds addressed: most-specific interface resolution, plus Hot Reload replacement of attribute and default handlers (scoped per app, reinstalled after removal). Each fix has tests that fail without it.<br>↑ Rebased onto the reviewed lower layers. Core 1,279 tests pass under dotnet test and xunit.console, and Controls 7,532 pass. Controls compiles for Android, iOS and MacCatalyst.<br>↑ The new Android compatibility-renderer default activation device test passes 3/3 on an emulator.<br>↓ CI and the full device suites on this head are not yet assessed.<br>↓ Windows paths are compile-only; no Windows device coverage is added. | <!-- /copilot-assessment --> <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change <!-- Enter description of the fix in this section --> Follow-up to #28357 targeting **main / .NET 12**. Rebased onto the trimmable-styles merge (#33561), `04d36966ed9d334c056872d83741e973d61f6c55`. #### Stack This PR is **layer 4 of 5** in a stack split from the original single PR for easier review. It is based on #40728, and its own diff covers only the attribute-based resolution: 1. #40721: context-aware handler activation and Hot Reload type matching. 2. #40725: mapper infrastructure that preserves app customizations, the `*ForControls` remap helpers and sealed framework mappings. 3. #40728: lazy Controls mapper remapping on first handler attachment. 4. **This PR**: `[ElementHandler]` attributes on Controls types, removal of the eager default DI registrations, resolution precedence and caches, Hot Reload cache invalidation, Material3 and Apple Shell attribute selection, Windows `PreventGestureBubbling` overrides and the constructor-argument diagnostic. 5. #40715: Copilot guidance for working with handlers and mappers. The sections below describe the combined feature; the activation, mapper and lazy-remap sections are reviewed in layers 1–3. The combined tree is unchanged from the reviewed `5db8263312bf8ea352e8f5a40b04e148c235f4cc` except for the follow-up below. Built-in Controls primarily declare `[ElementHandler]` instead of being rooted by an eager default DI registration table. Controls-specific mapper changes run lazily when handlers attach, while preserving recorded application customizations. Open review items are listed below; this description is not a merge-readiness approval. #### Attribute-based handler resolution `ElementHandlerAttribute` remains internal. The concrete handler type is statically referenced for trimming/AOT. Although the attribute has `Inherited = false`, the factory explicitly walks the base-type hierarchy for fallback. Nested control-specific attributes preserve conditional Android Material3 selection and Windows CollectionView handler selection without unconditionally referencing both alternatives on the active path. `GetHandler(Type)` and `GetHandlerType(Type)` share the resolution order: 1. Exact DI registration. 2. Attribute declared directly on the requested type. 3. The more specific of the nearest registered base class and the nearest inherited attribute. An inherited attribute ranks like the built-in registration its declaring class used to have; a registration on that class or a subclass wins. 4. The most specific registered interface. With Controls defaults on, the `IContentButton`/`IContentView` defaults compete here as interface registrations. 5. Content interface fallbacks: `IContentButton` → `ContentButtonHandler`, then `IContentView` → `ContentViewHandler`. A conditional attribute can declare no handler, for example Apple `ShellItem` when `UseiOSShellHandler` is off; resolution then continues as if it were absent. An exact `AddHandler` still overrides defaults. A registration for `Button` applies to an unannotated `FancyButton : Button`, but registering `IButton` or `View` does not divert it from `ButtonHandler`. Factory registrations remain authoritative even when `GetHandlerType` cannot report an `ImplementationType` and therefore returns `null`. Controls enables an `ElementHandlerDefaultsEnabled` policy per app's handler collection: `TryAddHandler` does not replace a directly declared default or the `IContentButton`/`IContentView` defaults, but still registers custom derived types that only inherit an attribute fallback. Apps without Controls defaults retain normal `TryAddHandler` behavior; `AddHandler` always remains an override. `UseMauiApp` enables the policy before registration callbacks execute regardless of builder-chain order. `AddMauiControlsHandlers` remains a non-obsolete compatibility no-op returning the original collection, without enabling defaults or eagerly remapping controls. #### Cache ownership and invalidation Only attribute and assignable-registration lookups are cached. The complete resolution result and constructor-activation strategy are **not** cached; current registrations and delegates are consulted on every request, and transient requests create fresh handlers. Each factory owns its resolution caches and builds its assignable index from current descriptors, including raw DI registrations. Built-in collection mutations (`Add`, `Insert`, indexer replacement, `Remove`, `RemoveAt`, `Clear`) advance a version. Hot Reload metadata updates, cache clearing, replaced-view callbacks and reset advance a checked generation before views are recreated. Hot Reload registration replacement also changes the collection version. A new cache generation replaces the old dictionaries, preventing concurrent old-generation readers from repopulating new state. Custom collections without mutation tracking do not retain resolution caches. Descriptor lookup stays consistent with indexer/list changes; removing the last registration restores the preceding descriptor for that service type. Cache lookup supports concurrent readers, but collection mutation retains the standard `IServiceCollection` contract and must not run concurrently with resolution. #### Context-aware activation without an activation cache `ElementExtensions.ToHandler` delegates reflection-based construction to the factory. A public parameterless constructor is preferred when present; otherwise `ActivatorUtilities.CreateInstance` resolves dependencies from the current context (including its Android context). Value-type handlers keep default construction. The constructor-presence check avoids using `MissingMethodException` as ordinary control flow, including first activation, without additional cache ownership/invalidation complexity. Direct public `GetHandler` callers retain parameterless-constructor behavior. Custom factories retain their existing exception-based injection fallback. Dependency failures propagate without retrying the entire injection. Factory activation still uses the current service provider/`IMauiContext`, and activated factory types participate in Hot Reload replacement. Historical matched **.NET 11** managed Release microbenchmarks measured warm injected activation at roughly 9 µs with exception-first construction versus 0.10–0.16 µs when missing-constructor exceptions were avoided. Constructor checks were comparable to a factory-owned activation cache; shared-host noise prevents claiming a small difference between those alternatives. These are **not .NET 12 measurements, Android startup claims, or APK-size results**. #### Lazy mapper remapping and main integration Controls `Element.SetHandler` invokes the remap hook before attaching any handler, including compatibility renderers. `ElementHandler.SetVirtualView` also invokes it for direct attachment outside Controls. Each remappable type calls its base hook and owns a blocking one-time initialization action; unrelated controls do not share a global initialization lock. Built-in mapper declarations seal their initial framework mappings. Controls property/command remaps update those mappings underneath recorded app customizations, preserving direct indexer overrides and `AppendToMapping`, `PrependToMapping`, `ModifyMapping`, and `ReplaceMapping` in registration order, including keys that are absent until a lazy remap and keys inherited from chained mappers. See `docs/design/HandlerResolution.md` for the ordering rules. Command-property dependency setup remains in control initialization, independent of handler attachment. The main rebase preserves newer upstream functionality: - `ContentButton` has its own handler attribute, `IContentButton` fallback, sealed mapper and lazy Android ripple remapping. - Switch OnColor remapping uses the lazy hook and customization-preserving prepend behavior on Apple platforms. - Android toolbar drawer-toggle remapping and the current Android/Windows common-mapping scope are retained. - RoundRectangle retains `IShapeWithStroke`; Shell retains the reentrant-navigation unsubscribe fix; handler instrumentation is preserved. - Android ListView/TableView/Frame compatibility attributes retain context-accepting activation through the factory's current-context injection path. - HybridWebView remains a deferred factory registration. Cell attributes retain their platform scopes, and Windows CollectionView feature-switch selection remains conditional. - Controls navigation-transition hooks are installed independently of the removed eager remapping helper. Obsolete eager registration/remapping helpers and Android-context-specific handler interfaces/attributes are removed. Detailed resolution and activation contracts are documented in `docs/design/HandlerResolution.md`. #### Updated Android APK measurements (.NET 12) **Trimmable styles + handlers reduce the plain template's signed NativeAOT APK by 756 KiB (4.64%) compared with neither optimization.** Since styles are already merged into main, this PR's incremental saving over styles alone is **712 KiB**. The 4.64% figure is the combined effect, not a handlers-only measurement. | Framework state | NativeAOT APK (bytes) | Release/CoreCLR APK (bytes) | | --- | ---: | ---: | | Neither styles nor handlers | 16,686,161 | 18,591,480 | | Trimmable styles only | 16,641,105 | 18,591,480 | | Trimmable styles + handlers | 15,912,017 | 18,398,968 | Styles alone save 44 KiB with NativeAOT. Ordinary Release/CoreCLR saves **188 KiB (1.04%)** with handlers; styles alone do not change that APK's size under its default settings. Measured the same unmodified `dotnet new maui -n Template --framework net12.0` source, **without `--sample-content`**, as signed ARM64 APKs. Framework revisions were `f38825f543a18fdcf5ac672b73835e50edd159f6` (neither), `04d36966ed9d334c056872d83741e973d61f6c55` (styles), and `9d2e9cf9b649b647777ec885cd31d1e303e3d49e` (both). The matched local builds use SDK `12.0.100-alpha.1.26523.103`, Android workload `37.99.0-preview.1.358`, and the same MAUI package version `12.0.0-pr29952.local`, with separate feeds/caches. Non-MAUI dependencies, runtime native libraries, signing key, app source and relevant build settings were matched and package hashes checked. NativeAOT uses full trimming and default trimmable styles; ordinary Release uses CoreCLR, partial trimming and default composite R2R. Both retain the SDK's default trimmable typemap and shipped/default profile policy: **no app-trained or custom MIBC**. These are APK file-size measurements, **not startup/JIT/runtime measurements**. No handlers-only arm was measured; the incremental handler saving includes its interaction with merged styles. Local artifact build commands (all **passed**): `bash artifacts/apk-styles-handlers-20261126/build-app.sh baseline aot`, `bash artifacts/apk-styles-handlers-20261126/build-app.sh none aot`, `bash artifacts/apk-styles-handlers-20261126/build-app.sh both aot`, and the same three commands with `release` instead of `aot`. The historical directory name `none` contains the styles-only revision; provenance is checked against `source.sha`, not inferred from directory labels. `python3 artifacts/apk-styles-handlers-20261126/measure.py` — **passed**; verifies all six APKs and records exact source/settings/package/profile identities in `results.json` alongside retained commands, logs and binlogs. These scripts and outputs are local investigation artifacts, not files added by this PR. #### Local validation after the styles rebase (9d2e9cf) The latest English-locale `net12.0` runs passed: - `LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 dotnet test src/Core/tests/UnitTests/Core.UnitTests.csproj -c Release -p:MauiPlatforms= -m:1 -v:q` — **1,198 passed**. - `LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj -c Release -p:MauiPlatforms= -m:1 -v:q` — **7,522 passed, 30 skipped**. - `LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj -c Release -p:MauiPlatforms= -m:1 -v:q` — **910 passed, 71 skipped**. The previously reported comma-decimal failures were independently reproduced on clean main and pass with the English locale; they are not this PR's regressions. Existing coverage includes collection mutation/raw registrations, custom unversioned collections, metadata and handler replacement, context/app isolation, dependency errors without retry, constructor preference/value types, first-use exception elimination, recorded mapper customization and ContentButton activation/type lookup. Local Android framework packaging and the six trimmed/NativeAOT template builds above passed. This does **not** establish device/UI behavior or iOS/MacCatalyst/Windows validation for this head; CI attribution and remaining review findings are still being assessed. #### Review follow-up in 714715d - **Handler precedence:** An inherited attribute ranks like the built-in registration its declaring class used to have. The most specific concrete candidate wins, and registered concrete types outrank interfaces. With Controls defaults on, `IContentButton`/`IContentView` defaults compete as interface registrations, and `TryAddHandler` no longer replaces them. - **Mapper customizations:** Lazy Controls remaps now compose underneath app customizations, as if they had run at startup. This covers post-seal assignments to absent keys, child customizations of parent keys that only appear in a later lazy remap, and delegates read before a remap. App-created mapper chains keep capture-at-customization semantics, and wrapping a mapping read from a mapper no longer recurses. - **Apple Shell:** `UseiOSShellHandler` again selects `ShellHandler` or `ShellRenderer`, along with the item, section and content handlers. Conditional attributes may declare no handler, so inactive handlers remain trimmable. - **CI fixes:** Hot Reload handler replacement matches by type name; xunit.console loads the test assembly twice. The Material3 Picker expectation is corrected, there is a blocking `OneTimeInitializationAction` test, and the constructor-argument diagnostic is clearer. Validation: Core unit tests passed 1,223/1,223 under `dotnet test` and xunit.console with `DOTNET_MODIFIABLE_ASSEMBLIES=debug`. Controls unit tests passed 7,530, with 30 skipped. `Controls.Core` compiles for `net12.0-ios27.1` and `net12.0-maccatalyst27.0`. The new Shell resolution device tests passed 2/2 on MacCatalyst via `.github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform maccatalyst -TestFilter "Category=Shell" -IncludeClasses "Microsoft.Maui.DeviceTests.ShellHandlerResolutionTests"`. Android and iOS device runs and CI are not yet assessed on this head, and the APK measurements above predate it. Follow-up in 5db8263: lazy RadioButton (Android) and TabbedPage remaps keep a `PlatformViewFactory` the app sets during startup. Resolution fetches its cache once per request, and the typed `*ForControls` mapper helpers check view and handler types before casting. Follow-up when splitting the stack: - Restores the iOS/MacCatalyst `UpdateCollectionViewAccessibilityTraits` refresh on semantics changes. A rebase in 7fba985 had accidentally dropped it. - `VisualElementMapperTests` trigger the lazy remap before reading global mapper keys. They previously passed only when another test had attached a handler first. - `HandlerResolution.md` gains the lower layers' more precise activation and remapping text. Validation on `c1de79de46`: - Core unit tests: 1,225 passed under `dotnet test` and xunit.console. - Controls unit tests: 7,530 passed, 30 skipped. - The three mapper key-order tests pass when run on their own. - `Controls.Core` compiles for `net12.0-android37.0`, `net12.0-ios27.1` and `net12.0-maccatalyst27.0`. Review follow-up (rebased; now in cdeafb7): - **Interface resolution:** resolution now picks the most specific matching interface before reporting an ambiguity. A concrete `IContentButton` with `IButton` and `IContentView` registered resolves to `ContentButtonHandler`, or to a registered `IContentButton` handler. Unrelated registrations remain ambiguous. - **Hot Reload:** pending handler replacements also apply to handlers resolved from `[ElementHandler]` or the content interface defaults. These have no collection descriptor, so the replacement is registered for the requested view type the next time it is resolved. - **Lower layers:** this PR was rebased onto #40728. That carries the lower layers' review fixes: injected handlers are never retained as singletons, the mapper fixes, and Label's public appends are back at type initialization. HandlerResolution.md now has a combined "Behavior changes" section with migration guidance. Second review round: - **Hot Reload:** replacements of attribute and default handlers apply only to the collection passed to `RegisterHandlers`. A newly registered collection receives replacements that were already applied to the previous one, and a replacement whose registration was removed is installed again. - **Registration order:** HandlerResolution.md documents the changes. `AddHandler` before `UseMauiApp()` now wins, `AddMauiControlsHandlers()` no longer restores a replaced handler, and `RemoveAll` followed by `TryAddHandler` no longer replaces an attributed default (use `AddHandler`). - **Android device test:** `CompatibilityRendererDefaultActivationTests` covers default activation of the `ListView`, `TableView` and `Frame` renderers with the current Android `Context`. Validation on `cdeafb7293`: - Core unit tests: 1,279 passed under `dotnet test` and xunit.console. - Controls unit tests: 7,532 passed, 30 skipped. - `Controls.Core` compiles for Android, iOS and MacCatalyst. - The Android device test above passed 3/3. Earlier validation on `a0f29fdbde`: - Core unit tests: 1,271 passed under `dotnet test` and xunit.console. - Controls unit tests: 7,531 passed, 30 skipped. - `Controls.Core` compiles for `net12.0-android37.0`, `net12.0-ios27.1` and `net12.0-maccatalyst27.0`. #### Behavior changes - **`AddMauiControlsHandlers()`:** Remains a compatibility no-op. Calling it after registering a custom handler, for example `AddHandler(typeof(Button), typeof(CustomButtonHandler))`, no longer restores `ButtonHandler`. Remove the custom registration instead. - **Custom `IMauiHandlersFactory` implementations:** Not supported. Built-in defaults are resolved from attributes by the built-in factory, not exposed as descriptors in `IMauiHandlersCollection`, so a replacement factory can no longer resolve Controls views. A follow-up will discourage and eventually remove this extension point. `IMauiContext.Handlers` exposes the interface, so this needs a replacement design rather than just `[Obsolete]`. - **Lazy remaps:** Controls mapper remaps run on each control type's first attachment instead of at `UseMauiApp`. App customizations made during startup are preserved as described above. Label keeps its pre-PR timing: its remaps already ran lazily from its static constructor. Windows CollectionView, ListView and TableView device coverage is left to the Windows controls maintainers. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Supports the trimmable handler work started in #28357. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
…ps (#40715) <!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `9fc89e163e09ad84e46d29176e995dc810548920` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 8.5/10 | ↑ Every rule was rechecked against the final restacked #29952 head (`cdeafb7`): the source, `docs/design/HandlerResolution.md` including its new Behavior changes section, and the resolved review threads.<br>↑ The committed Pester suite `Review-Expert.Tests.ps1` passes 13/13 locally with Pester 5.9.0. It checks the pinned hash, the 32 headings, mapper routing to dimension 3 with negative cases, and C# routing to dimensions 12 and 18. Its positive cases fail when the mapper rules are removed.<br>↓ The routing change has not been exercised in a live `/review` run, and I have not inspected the PowerShell Script Tests CI result for this head.<br>↓ No automated validation exists for instruction or agent files. The skill-validation workflow covers only `.github/skills/**`, which this PR does not change.<br>↓ The guidance follows the stack's design, so it must be revisited if a lower layer changes before merge. | <!-- /copilot-assessment --> <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change This is the top layer of the trimmable-handlers stack: 1. #40721: context-aware handler activation 2. #40725: customization-preserving mapper infrastructure 3. #40728: lazy Controls mapper remaps 4. #29952: trimmable `[ElementHandler]` resolution 5. **This PR**: agent guidance The base is the #29952 branch, `dev/simonrozsival/net10.0-use-element-handler-attributes`. Merge this PR after #29952 and the layers below it. It changes only agent guidance, expert-review routing and its tests, not product code. It records the stack's handler and mapper practices so future agents follow them: - **New `.github/instructions/handler-registration.instructions.md`**, path-scoped to Controls `*.Mapper.cs` partials, Core/Controls hosting, `Handlers/Element`, `PropertyMapper*`/`CommandMapper*`, `ElementExtensions`, Hot Reload, handler-resolution and mapper tests, and `HandlerResolution.md`. It covers: - **Built-in defaults:** built-in controls declare their default handler with the internal `[ElementHandler]` attribute on the control class (platform-scoped), not with DI. `AddMauiControlsHandlers()` is a no-op. DI is for app/library overrides and interfaces. HybridWebView's existing `SetupDefaults` factory is an exception to keep, not a pattern to copy: a factory delegate only defers construction, so the handler stays rooted. - **Construction:** attribute-resolved handlers need a public parameterless constructor. Only `ToHandler()` injects constructor arguments; a handler that needs them should be registered with an `AddHandler` factory. The factory's provider resolves the current `IMauiContext` only on context-taking paths such as `ToHandler()`, not on public `GetHandler(Type)`. There is no activation cache, and custom `IMauiHandlersFactory` implementations are unsupported. - **Feature switches:** handler selection that depends on a feature switch uses a nested `ElementHandlerAttribute` subclass that checks a `[FeatureSwitchDefinition]` switch (Material3, Windows CollectionView, Apple Shell). `GetHandlerType()` may return `null`. - **Resolution:** - It covers precedence, `GetHandler`/`GetHandlerType` consistency, interface ambiguity, Hot Reload replacement of attribute handlers, non-singleton injected handlers and `TryAddHandler` semantics. - To replace a built-in handler, use `AddHandler`; it wins regardless of registration order. - Mapper customization is documented as startup-only. - It links to `HandlerResolution.md` rather than duplicating it, and asks for observable changes to be recorded in that doc's Behavior changes section. - **Lazy remaps:** remaps run on first attach, base type first. `Toolbar`, which is not an element, triggers its remap from its own handler setter. - Remaps use the `*ForControls` helpers, not the public customization APIs. Label's Android `IsTextSelectable` and Apple `FlowDirection` public appends are the documented exception; they run from `static Label()`, not the remap. - Static factories are installed through `InstallPlatformViewFactory()` with `??=`, and `DependsOn` stays in type initialization. - Remapped mappers call `.WithFrameworkMappingsSealed()`. `SwitchHandler.Mapper` and `TextButtonMapper`/`ImageButtonMapper` remain unsealed exceptions. - A framework remap of an inherited key builds on the parent's mapping as it is at first attachment. - For inherited keys, sealed mappers return child-bound mappings and unsealed ones return the chained mapping. Internals use `PropertyMapper.GetPropertyDirect`. - **Testing:** - Platform attribute branches need device tests. Tests that toggle a switch use `DisableParallelization` and restore it. - Mapper-preservation tests cover customizations both before and after the remap. - Tests that read global mappers must trigger the lazy remap first (`new VisualElement().RemapForControls()`). - Tests must not assume `Type` identity across assembly loads. - **`handler-patterns.instructions.md`**: adds bullets on sealing (with the unsealed exceptions) and the remap helpers, plus a short "Registering Built-in Handlers" section that links to the new file. - **`maui-expert-reviewer.md`**: replaces the outdated "use `ModifyMapping` for Controls-layer overrides" check. - Dimension 3 gets checks for remaps, sealing, unsealed exceptions, child-key remaps, `??=`, `DependsOn` and test-order independence. - Dimension 12 gets checks for resolution consistency, unsupported custom factories and the `AddMauiControlsHandlers()` no-op. - Dimension 18 gets checks for attributes, feature-switch selection and device coverage. The existing HybridWebView factory is exempt from the built-in-handler check. - Dimensions 12 and 18 activate for every `.cs` file, both in the rulebook's Conditional Dimensions table and in `Review-Expert.ps1`. Self-reviews that pick dimensions from the rulebook, such as try-fix Step 6, therefore also reach the `[ElementHandler]` checks. - **Dimension Routing** now routes Controls `*.Mapper.cs` partials, Core mapper infrastructure (`PropertyMapper*`, `CommandMapper*`, `MappingCustomizationSequence.cs`) and `*Mapper*Tests.cs` to dimension 3, so mapper-only changes get the remap and test-order checks. - **`.github/scripts/Review-Expert.ps1`**: mirrors those three routing rules in `Get-ExpertExpectedDimensions` and updates the pinned routing SHA-256. This changes only routing data; it adds no tokens, checkouts or PR-code execution. - **New `.github/scripts/Review-Expert.Tests.ps1`**: Pester regression tests for the routing, run by the existing `powershell-script-tests.yml` gate. That workflow now also triggers on `.github/agents/maui-expert-reviewer.md`, so a rulebook routing edit without a matching hash update fails CI. - **`copilot-instructions.md`**: adds a short "Handlers and Mappers" pointer, because a focused `applyTo` cannot match control class files (`Label.cs`, `Button.cs`, ...). - **`README-AI.md`**: indexes the handler instruction files. No skills changed: `code-review` delegates handler checks to `maui-expert-reviewer`, and no other skill describes handler registration. **Validation:** No automated tests exist for instruction or agent markdown, and `skill-validation.yml` runs only for `.github/skills/**`. - `pwsh -c 'Import-Module Pester -RequiredVersion 5.9.0; Invoke-Pester .github/scripts/Review-Expert.Tests.ps1'`: **passed**, 13/13. - With the three mapper routing rules temporarily removed from `Review-Expert.ps1`, the same run failed 6 of 13 tests, so the suite catches the original gap. `git diff --check` is clean. ### Issues Fixed Follow-up to #29952; no separate issue. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
<!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `8c97daa2f6953333e3773e2366f67180d368ff2a` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 8/10 | ↑ Rebased conflict-free onto main `0806e8de4c`; main's only new netstandard guard (HotReloadHelper.cs) is removed, and remaining `NETSTANDARD` uses in libraries are in files linked into netstandard2.0 SourceGen.<br>↑ Platform-disabled net12.0+net11.0 builds of Core and Controls.Core (`IncludePreviousTfms=true`) and the netstandard2.0 Controls.SourceGen passed with 0 warnings and 0 errors.<br>↑ At this head: Graphics 406, Essentials 520, Core 1355, SourceGen 928 (71 skipped) and Xaml 1652 (3 skipped) tests passed.<br>↓ Controls.Core.UnitTests: 7740 passed, 30 skipped, 31 failed. These are the same 31 GC-collection leak tests that failed on the earlier base `77f939a75b`; they were not re-run on main `0806e8de4c`.<br>↓ Android/iOS/Mac Catalyst/Windows/macOS TFMs, packaging and external netstandard consumers not validated.<br>↓ CI pending or not inspected. | <!-- /copilot-assessment --> <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! > [!IMPORTANT] > **Intentional breaking change for review.** MAUI runtime libraries stop shipping `netstandard2.0`/`netstandard2.1` reference assets. External libraries that multi-target netstandard against MAUI, design-time tools and external backends may stop resolving compatible assets. Reviewers need to confirm this is acceptable for .NET 12 before merge; local test success does not answer the compatibility question. <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. This is .NET 12 modernization targeting `main`. XamlC removal (#40608) has merged (`77f939a75b9bd7434e5abf1ed603310597be692b`). This branch is rebased onto later main `0806e8de4c68667b01d434d4fd6d33ffdaebe761`. Main builds `net12.0`, with optional previous `net11.0`. This is the bottom layer of a stack; the later layers are project-specific performance PRs. ### Description of Change <!-- Enter description of the fix in this section --> With XamlC gone, MAUI runtime libraries no longer need netstandard targets. This shared prerequisite removes them and the version guards that became obsolete. It necessarily touches multiple projects and contains no performance changes. **1. Remove obsolete .NET version preprocessor conditions** (124 files) Removes `NET5`–`NET11` `*_OR_GREATER` conditions and similar guards that are always true on net12.0/net11.0. Guards still needed are kept: - `NET12_0_OR_GREATER` - guards in source generators - guards in emitted user code - guards in sources linked into netstandard2.0 tooling **2. Drop netstandard targets from MAUI libraries** (256 files, mostly deleted netstandard PublicAPI baselines) Removes `netstandard2.0`/`netstandard2.1` from these libraries: - Core - Controls.Core - Controls.Xaml - Essentials - Graphics and Graphics.Skia - Core and Controls Maps - Controls.NuGet - Core.ExternalBackend CustomAttributes, GraphicsTester.Portable and Graphics.Text.Markdig now use `$(_MauiDotNetTfm)`. The commit also: - removes the library-only netstandard PublicAPI baselines, package references and polyfills - simplifies `NETSTANDARD` branches in library-only code, keeping the default interface member branch (`ILabel.IsTextSelectable`, `IImage.Metadata`/`Save`/`SaveAsync`, `IImageLoadingService.FromStream(…, ImageLoadOptions?)`, `IQueryAttributable.ApplyQueryProperties`) - updates the ExternalBackend tests and docs **3. Remove the netstandard-only `ExperimentalAttribute` polyfill** `Controls/Core/Animations/ExperimentalAttribute.cs` was compiled only for `!NET8_0_OR_GREATER`, so it is now dead code. **4. Include Essentials/Graphics previous TFMs with `IncludePreviousTfms`** Previously, `-p:IncludePreviousTfms=true` built net11.0 Core/Controls against the netstandard2.1 Essentials/Graphics assets. Without those assets, restore failed with NU1201. `IncludePreviousTfmsEssentials`/`IncludePreviousTfmsGraphics` now default to `$(IncludePreviousTfms)`. Default builds stay net12.0-only, and an explicit `-p:IncludePreviousTfmsEssentials=false` still wins. **5. Remove the netstandard guard from `HotReloadHelper`** Newer main (aa118ce, #29952) added `#if !NETSTANDARD` around `[RequiresDynamicCode]` in `src/Core/src/HotReload/HotReloadHelper.cs`. Core no longer targets netstandard and no netstandard project links this file, so the guard is always true and has been removed. Main added no other netstandard guards or netstandard project references after #40608. **Tooling keeps netstandard2.0.** These projects still target `netstandard2.0`, so source linked into them must stay netstandard-compatible: - Controls.SourceGen - BindingSourceGen - HybridWebViewSourceGen - Build.Tasks - build/test tooling: DotNet, Workloads, Provisioning, TestUtils, VisualTestUtils Shared files linked into SourceGen keep their guards: XamlParseException, XmlName, XmlType, XamlNode, XamlParser, ColorUtils and AllowImplicitXmlnsDeclarationAttribute. This is not a repository-wide netstandard removal. **Rebase notes.** An earlier draft carried a commit restoring `NET11_0_OR_GREATER` guards, needed only while the parent snapshot targeted net11/net10. On main (net12/net11) those guards are always true, so the commit was dropped. Conflict resolutions: - `RemappingHelper.cs`: kept main's deletion (#40728). - `RuntimeFeature.cs`: kept main's removal of `IsQueryPropertyAttributeSupported`. - `iOS/ApplicationExtensions.cs`: kept main's formatting. - netstandard PublicAPI files that main had modified: deleted only after confirming all of main's additions exist in the `net` baselines. **Benchmarks:** this prerequisite claims no performance gains. Before/after measurements for the important operations are in the later project-specific PRs in this stack. **Validation** All results are at head `8c97daa2f6953333e3773e2366f67180d368ff2a`. Setup: - SDK `12.0.100-alpha.1.26523.103` from `global.json`, repo-local `./.dotnet`. - `$P` = `-p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false` - Tests ran with `LC_ALL=en_US.UTF-8`. | Command | Result | |---|---| | `dotnet build src/Core/src/Core.csproj $P -p:IncludePreviousTfms=true` | 0 warnings, 0 errors (Graphics, Essentials, Core for net12.0 + net11.0) | | `dotnet build src/Controls/src/Core/Controls.Core.csproj $P -p:IncludePreviousTfms=true` | 0 warnings, 0 errors (net12.0 + net11.0). Before commit 4: NU1201 (Essentials/Graphics not compatible with net11.0) | | `dotnet build src/Controls/src/SourceGen/Controls.SourceGen.csproj` | 0 warnings, 0 errors (netstandard2.0) | | `dotnet test src/Graphics/tests/Graphics.Tests/Graphics.Tests.csproj $P` | 406 passed, 0 failed | | `dotnet test src/Essentials/test/UnitTests/Essentials.UnitTests.csproj $P` | 520 passed, 0 failed | | `dotnet test src/Core/tests/UnitTests/Core.UnitTests.csproj $P` | 1355 passed, 0 failed | | `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj $P` | 928 passed, 71 skipped, 0 failed | | `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj $P` | 1652 passed, 3 skipped, 0 failed | | `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj $P` | 7740 passed, 30 skipped, 31 failed. All 31 failures are GC-collection leak assertions (`CommandsSubscribedToCanExecuteCollect` ×18, `LayoutDoesNotLeakAfterChildRemoved` ×4, `DoesNotLeak` ×2, `TransformGroupTests` ×3, `RowDefinitionDoesNotLeak`, `RemovingValueDoesNotLeak`, `RemovingLastValueDoesNotLeak`, `IndicatorViewItemsSourceDoesNotLeak`). An earlier run on base `77f939a75b` without this PR had the same 31 failures; they were not re-run on main `0806e8de4c` | **Not validated:** - Android/iOS/Mac Catalyst/Windows/macOS TFMs were not compiled locally. - Packaging and external netstandard consumers. - CI is still pending. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> N/A — .NET 12 framework prerequisite, no tracking issue. ### Let AI finish this PR - [ ] **Let the MAUI agent address review feedback and fix remaining issues on this PR.** Maintainers still decide whether it is merged. For PRs from forks, keep "Allow edits by maintainers" on so the agent can push to your branch; otherwise it opens a follow-up PR that keeps your commits. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
…ns survive (#40930) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change Since #28357, `Label`'s Controls remap ran only from `Label`'s static constructor. The remap uses `ReplaceMapping` for `Text`, `LineBreakMode`, `MaxLines`, `TextType`, `TextTransform` and `FormattedText`, which drops whatever is already mapped. An app that customizes `LabelHandler.Mapper` in `MauiProgram` (after `UseMauiApp`) lost those customizations as soon as the first `Label` was created. In .NET 9 the remap ran inside `UseMauiApp`, so app customizations layered on top of it. - `UseMauiApp` runs `Label`'s remap again, right after the `VisualElement` remap, as it did before #28357. - The `Label` static constructor and `UseMauiApp` both go through `RemappingHelper.RemapIfNeeded`, the guard `Element` and `VisualElement` already use. The remap runs once, whichever comes first. On `net11`, `AddControlsHandlers()` still registers `LabelHandler` eagerly, so running the remap at startup doesn't root anything that wasn't already rooted. On `main`, #40725 and #40728 fix this differently: customization-preserving mappers plus lazy remapping. That change is too large for servicing. `CheckBox` uses the same static-constructor pattern for `CheckBoxHandler.Mapper`'s `Color` key. It's left out of this PR to keep it focused. **Tests:** `LabelMapperCustomizationTests` runs the scenario against fresh copies of the MAUI assemblies in a collectible `AssemblyLoadContext`, because the `Label` type initializer only runs once per process. It calls `UseMauiApp`, appends `Text` and `LineBreakMode` mappings, creates a `Label`, and checks that both appended mappings run. **Validation:** - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter FullyQualifiedName~LabelMapperCustomizationTests` - Without the fix: **fails** (`Expected: ["Text", "LineBreakMode"]`, `Actual: []`). - With the fix: **passes**. - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj`: **passed**, 6840 tests, 0 failed, 30 skipped. - Not run: platform TFM builds, device tests and UI tests. The change contains no platform-specific code. ### Issues Fixed Fixes #40929 ### Let AI finish this PR - [ ] **Let the MAUI agent address review feedback and fix remaining issues on this PR.** Maintainers still decide whether it is merged. For PRs from forks, the agent opens a follow-up PR that keeps your commits. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
… initializers (#41206) <!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `f55e53f8cb45bc70f5529273116a30be6308c945` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 9/10 | ↑ Fresh-process concurrency harness: fix 0/200 hangs, restored 0/30.<br>↑ Core.UnitTests Release 1138/1138 x3; Controls.Core.UnitTests 6908 passed, 0 failed.<br>↓ CI on this PR not yet observed. | | Diagnosis confidence | 9.5/10 | ↑ dotnet-stack of a hung process shows Label..cctor holding the helper lock waiting on VisualElement, while VisualElement..cctor -> Element..cctor waits on the helper lock.<br>↑ Baseline 94/100 hung, reverted 29/30 hung. | | Evidence fit | 8.5/10 | ↑ CI hangs show exactly the first-use Controls tests (Label, ContentView, Button, DatePicker, Grid, mapper tests) all blocked at startup.<br>↓ CI createdump failed, so no CI-side stack confirms the identical cycle. | <!-- /copilot-assessment --> <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change **Symptom:** `maui-pr` on `candidate/11.0.1xx-sr3` intermittently fails "macOS unit tests (Release)". In about half of the runs, `Core.UnitTests` stalls with 11 tests blocked from startup until the hangdump timeout (exit 7). Examples: builds 1706437, 1706493, 1707019, 1707055, 1707205 and PR build 1707259. These hangs show up as failures because of the hang-dump infra from #41038. **Root cause:** `RemappingHelper` held a single global lock while running each Controls remap. #40930 changed `static Label()` to remap through the helper. Label's remap calls `VisualElement.RemapIfNeeded()`, which requires VisualElement's type initializer. With concurrent first use: - Thread A: `Label..cctor` → takes the helper lock → waits for `VisualElement..cctor` - Thread B: `VisualElement..cctor` (static brush field) → `Element..cctor` → `Element.RemapIfNeeded` → waits for the helper lock Neither thread can proceed, and the runtime does not detect a cycle that mixes a monitor with type-init locks. The `dotnet-stack` capture of a hung repro process shows exactly these two frames. **Fix:** keep the run-once state in a short global lock, but run each remap under a **per-type** lock. Same-type callers still wait for completion. Reentrancy on the same thread still returns immediately. A remap that throws is still not retried. Remaps of different types no longer block each other, and the type dependency chain (Label → VisualElement → Element) is acyclic. `main` removed this helper in a larger lazy-remap redesign (#40725/#40728), which is not appropriate for this candidate. ### Validation A fresh-process harness against the built assemblies creates `Label`, `ContentView`, `Button`, `BoxView`, `Grid` and `DatePicker` on 6 barrier-synchronized threads, with an 8 s join: | Tree | Hung | |---|---| | Baseline e69e972 | 94/100 | | Fix | 0/200 | | Fix reverted | 29/30 | | Restored | 0/30 | - `dotnet test --project src/Core/tests/UnitTests/Core.UnitTests.csproj -c Release`: 1138/1138 passed, 3 runs. - `dotnet test --project src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj -c Release`: 6908 passed, 0 failed (30 skipped). This includes `LabelMapperCustomizationTests` from #40930. ### Issues Fixed Fixes the intermittent macOS Release Core.UnitTests hang on `candidate/11.0.1xx-sr3`. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>


Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
837a686cae779f71c330b133bcfa58aa05f4b04cdf9d3fbaca. Core 1,235 tests pass underdotnet testand xunit.console. Controls 7,476 pass, 30 skipped.↑ A non-
ElementHandlerToolbar handler regression test fails without the latest fix and passes with it.↑ Mapper-related Controls test classes also pass when each runs alone.
↑ Device tests on the iOS 27 simulator and an Android emulator pass for the
Label,TabbedPageandRadioButtoncategories.↑ The new factory tests fail when
??=is changed to=.↑ Controls.Core compiles for Android, iOS and MacCatalyst with 0 warnings.
↑ Two code reviews found an order-dependent test and a test-restore problem, both fixed. They found no product issues.
↓ Windows was not compiled locally, and no UI tests were run.
↓ CI has not run on this head.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Target Branch
mainnet11, for reviewFor .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into
net11; agents must not retarget or merge.Description of Change
This is layer 3 of 5 in a stack that splits #29952 ("[trimming] Trimmable element handlers") into reviewable pieces. It is stacked on #40725 (base branch
simonrozsival-handlers-stack-l2-mapper-infrastructure, currentlydf9d3fbaca). The stack ultimately targetsmain(.NET 12).FullNamefix.[ElementHandler]attributes, removal of the eager DI default table, resolution precedence and caches.Controls used to apply all of its mapper remaps at startup:
UseMauiAppcalled every control's staticRemapForControls(), andElement,VisualElement,LabelandSwitchalso remapped from static constructors. This layer applies each remap the first time an instance of that type is attached to a handler. #29952 needs this so a control's remap code doesn't root that control's handler when the app never uses it. Layer 2's customization records make the change safe: on sealed mappers, app customizations compose with the Controls remaps whichever runs first.Mechanism
IControlsMapperRemappable, with a singleRemapForControls()method.OneTimeInitializationAction, a blocking execute-once action backed byLazy<bool>. Concurrent callers wait until the action completes. Tests are added for both behaviors.ElementHandler.SetVirtualView()callsRemapForControls()when the virtual view implementsIControlsMapperRemappable. The call runs afterVirtualViewis set and before the platform view is created and properties are mapped.Elementimplements the interface. TheElement.Handlersetter calls the hook beforeSetVirtualView, so compatibility renderers that don't derive fromElementHandlerare covered too.*.Mapper.csnow overridesinternal void RemapForControls(). The override callsbase.RemapForControls()and then runs a staticRemapForControlsOnce()through its ownOneTimeInitializationAction. Attaching aLabel, for example, runs theElement,VisualElementandLabelremaps in that order. Unrelated control types don't share a global lock.Toolbaris not anElement, so it implementsIControlsMapperRemappableitself. ItsHandlersetter calls the hook too, so custom toolbar handlers that don't derive fromElementHandlerare covered.RemappingHelper.csand the emptyLayout.Mapper.csare deleted.Switchstatic constructor, which only remapped, is removed.Label's static constructor now registers only its two publicAppendToMappingcalls, AndroidIsTextSelectableand AppleFlowDirection, which main also recorded atLabeltype initialization. Everything else in Label's remap runs lazily.CheckBoxkeeps its static constructor forCommandProperty.DependsOn(CommandParameterProperty). A test checks that the command dependency is set before any handler is attached.TabbedPageremap (TabbedViewHandler.PlatformViewFactory) and the AndroidRadioButtonremap (RadioButtonHandler.PlatformViewFactory) install their factory throughInstallPlatformViewFactory(), which uses??=. A factory the app installed before the first attach is kept. New device tests cover both an unset factory and an app factory installed first.Hosting
AppHostBuilderExtensions.SetupDefaultsno longer calls the eagerRemapForControlsbuilder extension, which is removed. It still registers the default handlers throughAddControlsHandlers(), and it still callsAnimations.ControlsNavigationTransitionHooks.Install(). That call used to run from inside the removed extension.ControlsDeviceTestExtensionsno longer calls the removed extension.Behavior changes
Lazy remapping is the intended .NET 12 behavior that makes trimming possible, so there is no runtime switch that restores startup remapping.
docs/design/HandlerResolution.mdlists these changes with migration guidance, next to layer 2's.UseMauiApp. On sealed mappers, app customizations compose with the Controls remaps no matter when they are registered, as described in layer 2.BackgroundColorredirect. Mappings already read throughGetProperty,GetCommandor the indexers still observe later remaps. Migration:new PropertyMapper<ILabel, ILabelHandler>(LabelHandler.Mapper) { ... }.AppendToMapping,PrependToMapping,ModifyMappingorReplaceMapping.HandlerChanged.UseMauiAppbut before that attachment. Migration: register customizations that should apply everywhere before the first control is attached, for example inMauiProgram, or customize the child mapper's key.TabbedPageor AndroidRadioButtonis attached is kept and replaces the Controls factory. Reading the property during startup to wrap the Controls factory now returnsnull.Label's two public appends are still recorded atLabeltype initialization.Deviations from the #29952 head (
5db8263312)VisualElement.Mapper.cskeeps the iOS/MacCatalystUpdateCollectionViewAccessibilityTraitscode from main. The [trimming] Trimmable element handlers #29952 head deleted it by accident.VisualElementMapperTeststests read global mapper keys without attaching a handler. They passed only when an earlier test in the same process had attached one. They now callnew VisualElement().RemapForControls()first. The affected tests areBackgroundKeyIsMappedBeforeControlsBackgroundColorAndImageSourceKeys,SemanticsKeyIsMappedBeforeControlsSemanticPropertiesKeysandRealDerivedHandlerMappers_MapCanonicalKeysBeforeTheControlsRedirectKeys. The [trimming] Trimmable element handlers #29952 head has the same order dependency.Switch.Mapper.cscomment now says "before the first Switch is attached to a handler" instead of "is created".Label.Mapper.csregisters the two public appends from a static constructor (#if ANDROID || IOS || MACCATALYST) instead of inside the lazy remap. This addresses review feedback on [trimming] Trimmable element handlers #29952 and on this PR.TabbedPage.Mapper.csandRadioButton.Mapper.csmove the??=install intoInstallPlatformViewFactory(). New device tests:TabbedPagePlatformViewFactoryTests.csandRadioButtonTests.Android.cs.TrySetValuemoves out ofElement.cs, theIElementHandler.csnewline fix,[ElementHandler]attributes, theAddMauiControlsHandlersno-op and the related device-test edits, and the WindowsPreventGestureBubblingrefactor.Docs
The "Controls mapper remapping" section of
docs/design/HandlerResolution.mdkeeps layer 2's mapper semantics and now describes lazy remapping. It covers:The section's "Behavior changes" list adds the lazy-remapping entries above to layer 2's entries.
Validation
Run with the .NET SDK
12.0.100-alpha.1.26523.103:dotnet build Microsoft.Maui.BuildTasks.slnfdotnet build src/Core/src/Core.csproj --disable-build-servers -nodeReuse:false(all local TFMs)LANG=en_US.UTF-8 dotnet test src/Core/tests/UnitTests/Core.UnitTests.csprojLANG=en_US.UTF-8 dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csprojartifacts/bin/Core.UnitTests/Debug/net12.0:DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet exec --roll-forward Major --runtimeconfig Microsoft.Maui.UnitTests.runtimeconfig.json --depsfile Microsoft.Maui.UnitTests.deps.json ~/.nuget/packages/xunit.runner.console/2.9.3/tools/netcoreapp2.0/xunit.console.dll Microsoft.Maui.UnitTests.dll -nocolordotnet test … Controls.Core.UnitTests.csproj --no-build --filter "FullyQualifiedName~.<Class>", run once per class, for 12 mapper-related classes (VisualElementMapperTests,ControlsMapperTests,ElementTests,VisualElementTests,ToolbarTests,LabelTests,RadioButtonTests,TabbedPageTests,HostBuilderHandlerTests,StoryboardTests,SemanticPropertyUnitTests,WindowsTests)dotnet build src/Controls/src/Core/Controls.Core.csproj -f net12.0-ios27.1 --disable-build-servers -nodeReuse:false-f net12.0-maccatalyst27.0and-f net12.0-android37.0pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform ios -TestFilter "Category=Label" -SkipXcodeVersionCheck(iOS 27 simulator)-Platform android -DeviceUdid emulator-5556… -Platform ios -TestFilter "Category=TabbedPage"… -Platform android -TestFilter "Category=TabbedPage"… -Platform android -TestFilter "Category=RadioButton"??=temporarily changed to=(iOS TabbedPage, Android RadioButton)dotnet format whitespace --folder --verify-no-changes --include <changed .cs files>git diff --checkNot run: Windows build, UI tests, CI.
Issues Fixed
Part of #29952.