Repository navigation
[net11.0][XAML] Preserve whitespace-padded names in runtime field lookups - #39568
Conversation
Preserve the original x:Name alongside the normalized generated field identifier, including across Hot Reload field reconciliation. Keep runtime namescope and style semantics unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: ba91d542-6d91-4dc8-b270-c1b5b57a958c
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39568Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39568" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🔵 Needs a closer look
Validation of the shared generator change remains unconfirmed because hosted CI and the reported local test results were not independently verified.
No open issues 🎉
What changed in this PR
Repairs the net11.0 XAML regression introduced by #39281 by preserving whitespace-padded runtime lookup names while keeping generated field identifiers trimmed.
Changes:
- Carries original XAML names through field reconciliation without changing retained field contracts.
- Uses safely quoted original names for direct and conditional runtime
FindByNamecalls. - Adds whitespace-edit and generated-code compilation coverage with incremental Hot Reload enabled and disabled.
| File | Description |
|---|---|
| src/Controls/tests/SourceGen.UnitTests/CodeBehindFieldStabilityTests.cs | Tests preserved lookup whitespace across edits in both Hot Reload modes. |
| src/Controls/src/SourceGen/CodeBehindCodeWriter.cs | Separates runtime lookup names from trimmed field identifiers. |
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.
|
/review expert-review |
This comment has been minimized.
This comment has been minimized.
|
|
||
| AssertNoErrors(diagnostics, updatedCompilation); | ||
| Assert.Contains("Label label0;", output, StringComparison.Ordinal); | ||
| Assert.Contains("FindByName<global::Microsoft.Maui.Controls.Label>(this, \" label0 \")", output, StringComparison.Ordinal); |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - Both XAML versions retain the same Label type, so the Hot Reload-enabled case exercises only the direct FindByName(Label) assignment, not the separately changed conditional FindByName(object) lookup. The neighboring type-change tests check SourceGen assignments or retained declarations rather than the runtime lookup key. Reverting only the conditional branch to the trimmed name would therefore escape these assertions: after an edit from Label to an assignable MyLabel with a whitespace-padded x:Name, runtime initialization would fail to assign the retained Label field. Add a Runtime generator case that changes the element type and name padding together, asserting the conditional lookup uses the current raw name while preserving the original field type.
PR Test Gate🧪 Gate analysis — click to expand✅ Passed. The selected verification satisfied the gate's passing conditions. Unmatched, skipped, or inconclusive groups are not passing evidence. 🧪 Unit tests
Execution log excerptsWithout fix With fix PR head: e4d0c17f. Without-fix baseline: 4ef2769e. |
|
@dalexsoto stamp |
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!
Description of Change
Intentionally targets net11.0, where #39281 introduced this regression.
CodeBehindCodeWriter.GetNamedFieldstrimsx:Namefor field identity and Hot Reload reconciliation. The runtime XAML loader still registers the original name. For the existingx:Name=" label0"fixture, generated runtime initialization therefore looks up"label0"instead of" label0", leaving the generated field null.Keep the original XAML name alongside the trimmed field identifier and use it for runtime
FindByNamecalls, including conditional assignments after Hot Reload type changes. Reconciliation uses the current XAML lookup name while preserving existing field contracts. Quote lookup keys with Roslyn's string-literal formatter.Runtime parsing, namescope registration,
StyleId, andx:Referencesemantics are unchanged. The originalMaui27121fixture andAssert.NotNull(page.label0)are unchanged. Add generator coverage for whitespace-only name edits with incremental Hot Reload enabled and disabled, including generated-code compilation.The original assertion is already failing in the target branch's build 1643728. This is a focused baseline repair, not a change to GC tests, device fixtures, packages, or pipelines.
Validation
Used the repository-pinned
11.0.100-rtm.26514.118SDK in a private installation, with platform-neutralnet11.0unit execution only. No Apple UI/XCTest execution.The exact
Maui27121.Tests.XNameAreTrimmed(inflator: Runtime)case was baseline red → fix green → fix reverted red → fix restored green. Both red runs failed the originalAssert.NotNullatMaui27121.xaml.cs:30. The full verification script ended withVERIFICATION PASSED; the worktree was clean after restoration.Commands and results:
The first Release attempt included previously emitted Debug
Generatedsources and failed with duplicate declarations. The command-only exclusion above removed those duplicate inputs; no project or pipeline configuration was changed. Full suites, Windows execution, and hosted CI are not claimed by these local results.Validated against base
3c9c033482797b64d878ef3f59bc6ac8a92f6ebd. The subsequent target update to7b0ea7800db3f3faccbaecb665d32b7c61eaf932does not change the relevant XAML source, tests, or dependency inputs. Open and recently merged upstream PRs were checked for the same issue/files/mechanism; no equivalent net11.0 fix was found. The cumulative inflight PR retains older raw-name handling but does not contain the net11.0 field reconciliation that this fix preserves.Hosted validation — build 1645738
Actual uploaded
testResults.xmlfiles from maui-pr 1645738, not aggregate badges, confirm the following for heade4d0c17f19b64b0bb20c9fafc96f0f77fa43371e/ merge9177af7ae9323da1e620ec8d6418f8e5b6bb8d7b:All eight assembly result files have zero failures and zero errors. The new cases are
CodeBehindFieldStabilityTests.RuntimeInflation_PreservesXNameWhitespaceInNameScopeLookup(enableIncrementalHotReload: False/True).Direct XML evidence: macOS Debug XAML, Windows Debug XAML, macOS Release XAML, Windows Release XAML. Generator XML files are in the same respective containers under
Microsoft.Maui.Controls.SourceGen.UnitTests.dll/1/testResults.xml.The raw Azure Helix monitor log reports four jobs processed, zero jobs/work items resubmitted, 46 work items submitted, and zero failed. At the bounded observation cutoff (2026-10-22 19:46 UTC), the overall build was still in progress: 28 of 31 jobs had succeeded;
Blazor windows,Build windows, andSamples macOSintegration jobs remained active. No failed timeline records were present at that cutoff. The focused unit-test evidence above is complete, but no overall CI or merge-readiness verdict is implied. The observation watch ended at its fixed deadline; no additional dispatches or retries were requested.Issues Fixed
Fixes the runtime regression of #27121 introduced by #39281, demonstrated by the existing
Maui27121.Tests.XNameAreTrimmedassertion.