Skip to content

Run Label's Controls mapper remap from UseMauiApp so app customizations survive - #40930

Merged
kubaflo merged 1 commit into
candidate/11.0.1xx-sr3from
stephanedelcroix-fix-label-mapper-init
Dec 1, 2026
Merged

kubaflo merged 1 commit into
candidate/11.0.1xx-sr3from
stephanedelcroix-fix-label-mapper-init

Conversation

@StephaneDelcroix

Copy link
Copy Markdown
Contributor

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

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

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 [net10.0] Trimmable view handlers #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.

Since #28357, Label's Controls remap ran from its static constructor, so its
ReplaceMapping calls discarded LabelHandler.Mapper customizations that the app
registered in MauiProgram before the first Label was created. Run it again from
UseMauiApp, guarded so the static constructor doesn't apply it twice.

Fixes #40929

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/autopilot-running MAUI Autopilot loop is running; remove this label to stop it label Dec 1, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the s/autopilot-reviewing MAUI Autopilot: MAUI expert review in progress label Dec 1, 2026
@github-actions github-actions Bot added the s/autopilot-retrying maui-expert-autopilot: retrying a step that failed once label Dec 1, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Expert Review — 1 finding · ⚠️ 1 breaking change

Reviewed commit 10ef5b8.

Warning

Existing apps would look or behave differently without opting in. See the Behavioral Change Disclosure findings at:

See inline comments for details.

Element.RemapIfNeeded();
Application.RemapForControls();
VisualElement.RemapIfNeeded();
Label.RemapIfNeeded();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[major] Behavioral Change Disclosure - Preserve inherited FlowDirection customizations on iOS/MacCatalyst. An app that calls ViewHandler.ViewMapper.AppendToMapping(nameof(IView.FlowDirection), ...) after UseMauiApp but before its first Label previously received that callback for Labels; with this change those Label callbacks stop running. Label.RemapForControls also appends its Apple FlowDirection mapping, and ModifyMapping immediately captures the inherited delegate and stores a local override on LabelHandler.Mapper. Running it here captures the parent before the app customizes it, permanently shadowing the later parent callback. This is separate from fixing discarded Text/LineBreakMode customizations. Preserve the previous parent-customization behavior, or provide an explicit compatibility opt-in and disclose the change. Add an Apple inherited-key regression case; the new neutral Text/LineBreakMode test cannot detect this.

@github-actions github-actions Bot added s/autopilot-fixing MAUI Autopilot: fixing review findings or failing tests (GPT-6.2 Sol vs MAI Code 2) and removed s/autopilot-retrying maui-expert-autopilot: retrying a step that failed once s/autopilot-reviewing MAUI Autopilot: MAUI expert review in progress s/autopilot-running MAUI Autopilot loop is running; remove this label to stop it s/autopilot-fixing MAUI Autopilot: fixing review findings or failing tests (GPT-6.2 Sol vs MAI Code 2) labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

MAUI Autopilot — Stopped

@kubaflo ❌ The last fix round found nothing more it could fix. Decide how to continue, or comment /review autopilot to run it again.

Why

No fix was published: the push check rejected paths in the branch history even though the new commit (247a95ad16) changes only src/. The review thread remains open.

[Run](https://github.com/dotnet/maui/actions/runs/46605854349).

@github-actions github-actions Bot added the s/autopilot-needs-maintainer-decision MAUI Autopilot stopped: a maintainer needs to decide how to continue label Dec 1, 2026
@StephaneDelcroix

This comment has been minimized.

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@kubaflo
kubaflo changed the base branch from net11 to candidate/11.0.1xx-sr3 December 1, 2026 12:40
@kubaflo
kubaflo merged commit b0c1c5f into candidate/11.0.1xx-sr3 Dec 1, 2026
13 of 14 checks passed
@kubaflo
kubaflo deleted the stephanedelcroix-fix-label-mapper-init branch December 1, 2026 12:41
kubaflo added a commit that referenced this pull request Dec 1, 2026
…ed PRs) (#40964)

<!-- copilot-assessment:v1 -->
### Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: `4a4404f49fcad2f2a633f42fcb8593d79f41015b`

| Dimension | Assessment | Rationale |
|---|---|---|
| Change confidence | 8.5/10 | ↑ `gh aw compile` passes; pre_activation
script stays under the 20.5 KB expression limit.<br>↑ `node --check`
passes on pre_activation and next_round.<br>↑ Unchanged-PR guard
replayed on 12 real result-labelled PRs: 10 skip, the 2 with new human
comments (#40930, #40933) still run.<br>↓ Two-model fix quality and the
round cap are not yet observed live. |
<!-- /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

MAUI Autopilot spent about 38k AI credits in 6 hours (95 runs, about 100
model requests per fix round). This cuts the main drivers:

- **Two models per fix round.** GPT-6.2 Sol and MAI Code 2 propose,
critique each other and revise; the Claude Opus 5.5 candidate (a
separate workflow run per round) is no longer requested. The prompt,
triage (a failure is `unrelated` only when both models agree) and docs
are updated. The `opus_run` input stays accepted so in-flight Opus runs
can still hand back without a dispatch error.
- **At most 3 fix rounds per `/review autopilot`.** Some PRs ran 5–8
rounds. After 3 the loop stops with
`s/autopilot-needs-maintainer-decision`; another `/review autopilot`
allows 3 more. Conflict merges don't count.
- **Don't rerun on an unchanged PR.** If the PR already has
`s/autopilot-waiting-for-maintainer-review` or
`s/autopilot-needs-maintainer-decision` and nothing changed since that
result (no new commits, human comments or reviews, no merge conflict),
`/review autopilot` replies with a link to the last result instead of
starting over. Removing the label forces a run.

Related: #40963 stops a tests round that publishes nothing from
repeating.

Validation: `gh aw compile maui-expert-autopilot`; `node --check` on the
changed scripts; replay of the unchanged-PR guard against real PRs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 10ef5b8d Deployed Dec 1, 2026 by StephaneDelcroix via conclusion #3567
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

s/autopilot-needs-maintainer-decision MAUI Autopilot stopped: a maintainer needs to decide how to continue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LabelHandler.Mapper customizations made in MauiProgram are discarded when the first Label is created

2 participants