Repository navigation
[XSG] XIHR: recover from rude edits that fail to compile - #40235
Conversation
A XAML edit whose generated code does not compile never reaches the running app, but XamlHotReloadState had already advanced to it. The next (fixed) edit was diffed against the broken generation, so changes made together with the rude edit (property sets, added elements) were never applied. Capture the state entry before diffing a XAML edit and restore it when the generation reports a build-breaking error (honoring NoWarn/editorconfig severity overrides) or emits IC/UC code with C# syntax errors, or throws. Fixes #36156 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 40235Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 40235" |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
/rebase |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
PR Test Gate
🧪 Gate analysis — click to expand⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect. No interpretable test-group summary was produced. No additional test execution is inferred. Setup did not capture a verified PR head; no commit is claimed as tested. No immutable without-fix baseline was prepared. |
|
|
||
| static bool FailsBuild(Diagnostic diagnostic, Compilation compilation, CancellationToken cancellationToken) | ||
| { | ||
| if (diagnostic.Severity != DiagnosticSeverity.Error || diagnostic.IsSuppressed) |
There was a problem hiding this comment.
[major] Logic and Correctness Verification - Evaluate the effective severity before excluding warnings. The observer sees the original diagnostic, so this early return ignores warnings promoted to errors by SpecificDiagnosticOptions/WarnAsError or global warning-as-error settings. For example, promote MAUIG2045 to an error, then change a valid typed binding to {Binding Missing} while changing a sibling label from "One" to "Two". KnownMarkups reports the warning and emits syntactically valid fallback binding code, so neither reportedError nor HasSyntaxErrors triggers rollback even though the generation cannot build. Fixing only the binding then diffs against the unapplied generation and omits the "Two" assignment, leaving the live label at "One". Resolve per-ID/global severity and warning-as-error policy before deciding whether the diagnostic fails the build, and add the promoted-warning/repair regression alongside the existing downgrade test.
This comment has been minimized.
This comment has been minimized.
Tests Failure Analysis
🧪 CI Analysis — click to expand📊 maui-pr
🧪 maui-pr-devicetests
🧪 maui-pr-uitestsMatches below reproduce assertions/stacks in comparable CoreCLR legs on net11, without these XIHR rollback changes. Target sampling is partial; absent matches remain unresolved.
🧭 Follow-up — actions and refreshNext action: Compare unresolved failures with identical target configurations; retrieve missing Helix diagnostics/results and visual attachments.
|
Preserve cache capture and restore alongside the repeated-evaluation patch baseline and source fingerprint metadata. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Resolved the conflicts with Combined the PR’s cache capture/restore for failed rude edits with the target’s repeated-evaluation patch baseline and user-source fingerprint metadata. Recovery retains the pending-patch state when restoring the previous generation, while repeated evaluations can still re-derive their patch. Both regression suites remain intact. |
<!-- 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). This PR targets `candidate/11.0.1xx-sr2`, not `net11`. It's a follow-up to #40235, which was merged into `candidate/11.0.1xx-sr2` and isn't in `net11` (or `main`) yet. The change builds on the code #40235 added. 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 Follow-up to #40235 (fix for #36156). #40235 rolls back the XAML Incremental Hot Reload state (`XamlHotReloadState.Restore`) when a XAML edit can't build. It checks three things: the generator reported an error, the generated IC/UC has C# **syntax** errors, or generation threw. It deliberately skipped **semantic** errors. Members added by other generators (CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`) aren't visible to the XAML generator, so a naive type check would roll back valid edits. As a result, an edit that only fails type checking, such as `{Count.Nope()}` (CS1061), still advanced the baseline. The next valid edit was then diffed against a generation the app never received, and the changes made together with the rude edit were lost. **Fix:** `HasSemanticErrors` type-checks the generated `InitializeComponent` and `UpdateComponent` trees against the generator's compilation (user code plus generated code-behind). It runs only when a XAML edit was diffed, i.e. when a rollback snapshot exists. An error counts only if: - it is located in the generated IC/UC code (errors in user code are ignored), and - `MayBeFixedByAnotherGenerator` returns false for it. That helper ignores errors that a declaration added by another generator could resolve: - unresolved names, types and namespaces (CS0103, CS0234, CS0246, CS0426); - failed member lookup (CS1061, CS0117, …) or overload resolution on a receiver whose type is a **`partial` type declared in source**, the only kind of type other generators can add members to. This also covers `?.` member bindings, implicit-`this` invocations, object creations, and errors reported on an argument. **Options considered:** - *Defer the baseline commit until a later signal confirms the compile.* Rejected: inside the generator there is no such signal. The next run's input compilation never contains the previous output, and nothing tells the generator whether the emit or EnC apply succeeded. - *Count all semantic errors.* Rejected: false rollbacks for MVVM Toolkit members. A false positive is worse than a miss, because the next patch re-adds children that are already live. - *Restrict to diagnostics attributable to XAML-generated code and filter out what another generator could fix.* Chosen. **Known remaining gap:** a lookup on a non-`partial` or metadata type (e.g. `int`) that only an extension method from *another generator* could satisfy still counts as an error. That's rare in XAML expressions. C# 14 extension members generated elsewhere fall in the same case. `XamlHotReloadState` is unchanged. The change is limited to `XamlGenerator.cs`, to keep conflicts with the #40233 follow-up low. **Tests** (`XamlIncrementalHotReloadRudeEditTests`): - `EditAfterRudeEdit_IsDiffedAgainstLastAppliedGeneration(Semantic)`: new case for a type-check-only rude edit, `{Count.Nope()}`. The theory parameter changed from `bool` to a `RudeEdit` enum. - `ElementAddedWithSemanticRudeEdit_IsAddedOnceTheEditIsFixed`: an element added together with a semantic rude edit is added once the edit is fixed. - `MembersGeneratedByAnotherGenerator_DoNotRollBack`: guard. The view model uses `[ObservableProperty]` and `[RelayCommand]`, and the XAML references `Count` (C# expression) and `{Binding SaveCommand}`. The previous edit must not be rolled back, so the added `Button` isn't added again. Without the fix, the 2 semantic cases fail. With `MayBeFixedByAnotherGenerator` disabled, the guard fails. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter FullyQualifiedName~XamlIncrementalHotReloadRudeEditTests`: **9 passed**. Before the fix: 2 failed (the semantic cases), 7 passed. With the filter disabled: 1 failed (the MVVM guard). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` (full suite): **772 passed, 0 failed, 53 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj` with `-p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false`. The mobile TFMs were excluded because of a local workload mismatch. Result: **2250 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) are known and depend on the machine's locale. - `dotnet format whitespace --folder --include <changed files> --verify-no-changes`: clean. ### Issues Fixed Follow-up to #40235. Relates to #36156. <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
<!-- 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 XAML Incremental Hot Reload (XIHR) keeps per-file state in `XamlHotReloadState` (last XAML, parsed tree, node IDs) and emits `UpdateComponent()` as a diff from the previous generation to the current one. A **rude edit** is a XAML edit whose generated code doesn't compile, for example a malformed XAML C# expression, or an error reported by the generator such as an unresolved member. The build fails, so that edit never reaches the running app. The state had already moved to the broken generation, though. The next, fixed edit was then diffed against the broken generation, not against what the app is running. Changes made together with the rude edit were never applied: property sets, and elements added in the same edit. They stayed lost until a full restart. **Fix:** - Before diffing a XAML edit, the generator captures a copy of the file's state entry (`XamlHotReloadState.Capture`). - After generating `InitializeComponent` and `UpdateComponent`, it restores that entry (`XamlHotReloadState.Restore`) when the generation can't build: - the generator reported an error while generating `InitializeComponent`. A new optional `diagnosticObserver` on `GenerateInitializeComponent` reports these. User severity overrides are honored (`NoWarn`, `WarningsNotAsErrors`, `.editorconfig`/`.globalconfig`), so a downgraded MAUIX error doesn't count; - or the generated IC/UC code has C# **syntax** errors; - or generation throws. - The next edit is then diffed against the last generation that could have been applied. Its patch also carries the changes made together with the rude edit. Re-evaluating the rude edit is deterministic, and reverting to the applied XAML is "no change". **Deliberately not checked: semantic C# errors** in the generated code, such as `{Count.Nope()}` (CS1061). Generated code can legitimately reference members that other generators add later, such as CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`, which `ITypeSymbolExtensions` already infers. A false positive is worse than a miss: it pins the state to a generation the app has already moved past, and the next patch would re-add children, for example. Those edits keep today's behavior. A C#-only compile failure that happens at the same time as a XAML edit is also out of scope. **Interaction with #40233 (fix for #36937):** The two are independent, so this PR is not stacked on #40233. #40233 adds `PatchBaseline`/`PatchSources` to `CacheEntry` and replays the pending patch when the same inputs are evaluated again. This PR snapshots and restores the whole `CacheEntry` with `MemberwiseClone`, so after a rebase, rolling back a rude edit also restores those fields. The restored state is exactly what the applied generation left, so the output for identical inputs stays identical. Expected conflicts are textual only, in `XamlGenerator.cs` (adjacent lines in the IC output callback) and `XamlHotReloadState.cs`. The new tests are in their own file to avoid conflicts in `XamlIncrementalHotReloadPipelineTests.cs`. **Tests:** new `XamlIncrementalHotReloadRudeEditTests` (6 cases): - an edit after a rude edit carries the changes made with the rude edit, for both a C# syntax error and a generator-reported error (MAUIX2009); - an element added with a rude edit is added once the edit is fixed; - reverting after a rude edit emits the same output as the applied state; - repeated evaluation of a rude edit is deterministic; - an error the user downgraded doesn't roll back (no duplicate element). The first 5 cases fail without the fix. The downgrade case fails if the severity lookup is removed. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter XamlIncrementalHotReloadRudeEditTests`: 6 passed; 5 failed before the fix. - SourceGen.UnitTests, full suite. It was run from a copy of the output in a path without `~`, because the `XTypeMultiFileHotReloadTests` fail when the path contains `~`. Result: **634 passed, 0 failed, 40 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`, built with Apple/Android TFMs excluded because of a local workload mismatch. Result: **2179 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) depend on the dev machine's locale (comma decimal separator) and pass with `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1`. - `dotnet format whitespace --verify-no-changes` on the changed files: clean. ### Issues Fixed Fixes #36156 <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
<!-- 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). This PR targets `candidate/11.0.1xx-sr2`, not `net11`. It's a follow-up to #40235, which was merged into `candidate/11.0.1xx-sr2` and isn't in `net11` (or `main`) yet. The change builds on the code #40235 added. 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 Follow-up to #40235 (fix for #36156). #40235 rolls back the XAML Incremental Hot Reload state (`XamlHotReloadState.Restore`) when a XAML edit can't build. It checks three things: the generator reported an error, the generated IC/UC has C# **syntax** errors, or generation threw. It deliberately skipped **semantic** errors. Members added by other generators (CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`) aren't visible to the XAML generator, so a naive type check would roll back valid edits. As a result, an edit that only fails type checking, such as `{Count.Nope()}` (CS1061), still advanced the baseline. The next valid edit was then diffed against a generation the app never received, and the changes made together with the rude edit were lost. **Fix:** `HasSemanticErrors` type-checks the generated `InitializeComponent` and `UpdateComponent` trees against the generator's compilation (user code plus generated code-behind). It runs only when a XAML edit was diffed, i.e. when a rollback snapshot exists. An error counts only if: - it is located in the generated IC/UC code (errors in user code are ignored), and - `MayBeFixedByAnotherGenerator` returns false for it. That helper ignores errors that a declaration added by another generator could resolve: - unresolved names, types and namespaces (CS0103, CS0234, CS0246, CS0426); - failed member lookup (CS1061, CS0117, …) or overload resolution on a receiver whose type is a **`partial` type declared in source**, the only kind of type other generators can add members to. This also covers `?.` member bindings, implicit-`this` invocations, object creations, and errors reported on an argument. **Options considered:** - *Defer the baseline commit until a later signal confirms the compile.* Rejected: inside the generator there is no such signal. The next run's input compilation never contains the previous output, and nothing tells the generator whether the emit or EnC apply succeeded. - *Count all semantic errors.* Rejected: false rollbacks for MVVM Toolkit members. A false positive is worse than a miss, because the next patch re-adds children that are already live. - *Restrict to diagnostics attributable to XAML-generated code and filter out what another generator could fix.* Chosen. **Known remaining gap:** a lookup on a non-`partial` or metadata type (e.g. `int`) that only an extension method from *another generator* could satisfy still counts as an error. That's rare in XAML expressions. C# 14 extension members generated elsewhere fall in the same case. `XamlHotReloadState` is unchanged. The change is limited to `XamlGenerator.cs`, to keep conflicts with the #40233 follow-up low. **Tests** (`XamlIncrementalHotReloadRudeEditTests`): - `EditAfterRudeEdit_IsDiffedAgainstLastAppliedGeneration(Semantic)`: new case for a type-check-only rude edit, `{Count.Nope()}`. The theory parameter changed from `bool` to a `RudeEdit` enum. - `ElementAddedWithSemanticRudeEdit_IsAddedOnceTheEditIsFixed`: an element added together with a semantic rude edit is added once the edit is fixed. - `MembersGeneratedByAnotherGenerator_DoNotRollBack`: guard. The view model uses `[ObservableProperty]` and `[RelayCommand]`, and the XAML references `Count` (C# expression) and `{Binding SaveCommand}`. The previous edit must not be rolled back, so the added `Button` isn't added again. Without the fix, the 2 semantic cases fail. With `MayBeFixedByAnotherGenerator` disabled, the guard fails. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter FullyQualifiedName~XamlIncrementalHotReloadRudeEditTests`: **9 passed**. Before the fix: 2 failed (the semantic cases), 7 passed. With the filter disabled: 1 failed (the MVVM guard). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` (full suite): **772 passed, 0 failed, 53 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj` with `-p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false`. The mobile TFMs were excluded because of a local workload mismatch. Result: **2250 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) are known and depend on the machine's locale. - `dotnet format whitespace --folder --include <changed files> --verify-no-changes`: clean. ### Issues Fixed Follow-up to #40235. Relates to #36156. <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
…ns (#40378) <!-- 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! ### 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). > [!IMPORTANT] > **Base: `candidate/11.0.1xx-sr2` (decided).** This PR builds on #40233, #40235, #40329 and #40330, which exist only on `candidate/11.0.1xx-sr2` (not on `net11`, `main` or `inflight/11.0.1xx-sr3`). Against `net11` the diff would include about 527 unrelated files. As with #40329 and #40330, it targets `candidate/11.0.1xx-sr2` directly so it ships together with its prerequisites. ### Description of Change #40330 left one limitation. A throwaway generator run with different XAML, such as a design-time or speculative run whose output never reaches the app, advanced the cached previous XAML. The next real `UpdateComponent()` was then diffed from that intermediate generation instead of the generation the running app actually has. The result was missed edits: for example, an edit already present in the throwaway XAML was never applied. The generator cannot tell which of its runs reached the app, so this PR has `UpdateComponent()` decide at runtime: - **Generation key.** Each successful generation gets a key: a SHA-256 of the normalized XAML plus the node IDs (`NodeIdHelper.ComputeGenerationKey`). `XamlHotReloadState` keeps the current generation and the previously generated ones as baselines, up to `MaxBaselines = 4`. - **InitializeComponent** records `XamlComponentRegistry.Register(this, "__xihr_generation:<type>", key)`. - **UpdateComponent** reads the instance's recorded key: - A retained generation whose diff produces exactly the current node IDs gets its own branch: the patch diffed from that generation. - Anything else gets the default patch, diffed from the last generated XAML. This matches the previous behavior. - Every patched instance then records the new key, so running the patch again, or for a C#-only edit, changes nothing. - When there is nothing to patch, the output is unchanged: an empty UC, with no marker. Rude-edit rollback behavior is preserved, and the older applied generation now also gets its own branch. **Known edge, not a regression:** a retained generation whose diff would assign different IDs from the current ones (e.g. some reverts) is not given a branch. Instances at that generation fall back to the default patch, which is the old behavior. ### Issues Fixed Fixes #36937 (remaining limitation from #40330) ### Tests - `XamlIncrementalHotReloadE2ETests.ThrowawayRunWithDifferentXaml_PatchStartsFromTheAppliedGeneration`: real metadata update. Applied `Text="Hello"`, then a throwaway run with `Text="World" FontSize="30"`, then the real edit to `Text="World"`. The live label ends at `World` with its default `FontSize`, re-running UC is a no-op, and new instances are already current. A new harness hook, `GenerateWithThrowawayRuns`, runs and discards a forked driver run. - `XamlIncrementalHotReloadPipelineTests.ThrowawayRunWithDifferentXaml_PatchesFromEveryRetainedGeneration`: checks the branch structure and determinism (same snapshot and C#-only edits give an identical UC). - `XamlIncrementalHotReloadPipelineTests.RetainedGenerations_AreBounded` - Existing rude-edit assertions now target the default patch (`UpdateComponentText.DefaultPatch`), because the UC legitimately contains a branch for the older applied generation. ### Validation - `DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: **passed**, 899/899. - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~HotReload"`: **passed**, 12/12. - `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2274 passed, 12 failed. All 12 failures are `CultureNotFoundException` from culture-specific tests under invariant-globalization mode; none involve hot reload. - `dotnet format whitespace Microsoft.Maui.sln --verify-no-changes --include <changed files>`: **passed**. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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 XAML Incremental Hot Reload (XIHR) keeps per-file state in `XamlHotReloadState` (last XAML, parsed tree, node IDs) and emits `UpdateComponent()` as a diff from the previous generation to the current one. A **rude edit** is a XAML edit whose generated code doesn't compile, for example a malformed XAML C# expression, or an error reported by the generator such as an unresolved member. The build fails, so that edit never reaches the running app. The state had already moved to the broken generation, though. The next, fixed edit was then diffed against the broken generation, not against what the app is running. Changes made together with the rude edit were never applied: property sets, and elements added in the same edit. They stayed lost until a full restart. **Fix:** - Before diffing a XAML edit, the generator captures a copy of the file's state entry (`XamlHotReloadState.Capture`). - After generating `InitializeComponent` and `UpdateComponent`, it restores that entry (`XamlHotReloadState.Restore`) when the generation can't build: - the generator reported an error while generating `InitializeComponent`. A new optional `diagnosticObserver` on `GenerateInitializeComponent` reports these. User severity overrides are honored (`NoWarn`, `WarningsNotAsErrors`, `.editorconfig`/`.globalconfig`), so a downgraded MAUIX error doesn't count; - or the generated IC/UC code has C# **syntax** errors; - or generation throws. - The next edit is then diffed against the last generation that could have been applied. Its patch also carries the changes made together with the rude edit. Re-evaluating the rude edit is deterministic, and reverting to the applied XAML is "no change". **Deliberately not checked: semantic C# errors** in the generated code, such as `{Count.Nope()}` (CS1061). Generated code can legitimately reference members that other generators add later, such as CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`, which `ITypeSymbolExtensions` already infers. A false positive is worse than a miss: it pins the state to a generation the app has already moved past, and the next patch would re-add children, for example. Those edits keep today's behavior. A C#-only compile failure that happens at the same time as a XAML edit is also out of scope. **Interaction with #40233 (fix for #36937):** The two are independent, so this PR is not stacked on #40233. #40233 adds `PatchBaseline`/`PatchSources` to `CacheEntry` and replays the pending patch when the same inputs are evaluated again. This PR snapshots and restores the whole `CacheEntry` with `MemberwiseClone`, so after a rebase, rolling back a rude edit also restores those fields. The restored state is exactly what the applied generation left, so the output for identical inputs stays identical. Expected conflicts are textual only, in `XamlGenerator.cs` (adjacent lines in the IC output callback) and `XamlHotReloadState.cs`. The new tests are in their own file to avoid conflicts in `XamlIncrementalHotReloadPipelineTests.cs`. **Tests:** new `XamlIncrementalHotReloadRudeEditTests` (6 cases): - an edit after a rude edit carries the changes made with the rude edit, for both a C# syntax error and a generator-reported error (MAUIX2009); - an element added with a rude edit is added once the edit is fixed; - reverting after a rude edit emits the same output as the applied state; - repeated evaluation of a rude edit is deterministic; - an error the user downgraded doesn't roll back (no duplicate element). The first 5 cases fail without the fix. The downgrade case fails if the severity lookup is removed. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter XamlIncrementalHotReloadRudeEditTests`: 6 passed; 5 failed before the fix. - SourceGen.UnitTests, full suite. It was run from a copy of the output in a path without `~`, because the `XTypeMultiFileHotReloadTests` fail when the path contains `~`. Result: **634 passed, 0 failed, 40 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`, built with Apple/Android TFMs excluded because of a local workload mismatch. Result: **2179 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) depend on the dev machine's locale (comma decimal separator) and pass with `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1`. - `dotnet format whitespace --verify-no-changes` on the changed files: clean. ### Issues Fixed Fixes #36156 <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
<!-- 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). This PR targets `candidate/11.0.1xx-sr2`, not `net11`. It's a follow-up to #40235, which was merged into `candidate/11.0.1xx-sr2` and isn't in `net11` (or `main`) yet. The change builds on the code #40235 added. 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 Follow-up to #40235 (fix for #36156). #40235 rolls back the XAML Incremental Hot Reload state (`XamlHotReloadState.Restore`) when a XAML edit can't build. It checks three things: the generator reported an error, the generated IC/UC has C# **syntax** errors, or generation threw. It deliberately skipped **semantic** errors. Members added by other generators (CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`) aren't visible to the XAML generator, so a naive type check would roll back valid edits. As a result, an edit that only fails type checking, such as `{Count.Nope()}` (CS1061), still advanced the baseline. The next valid edit was then diffed against a generation the app never received, and the changes made together with the rude edit were lost. **Fix:** `HasSemanticErrors` type-checks the generated `InitializeComponent` and `UpdateComponent` trees against the generator's compilation (user code plus generated code-behind). It runs only when a XAML edit was diffed, i.e. when a rollback snapshot exists. An error counts only if: - it is located in the generated IC/UC code (errors in user code are ignored), and - `MayBeFixedByAnotherGenerator` returns false for it. That helper ignores errors that a declaration added by another generator could resolve: - unresolved names, types and namespaces (CS0103, CS0234, CS0246, CS0426); - failed member lookup (CS1061, CS0117, …) or overload resolution on a receiver whose type is a **`partial` type declared in source**, the only kind of type other generators can add members to. This also covers `?.` member bindings, implicit-`this` invocations, object creations, and errors reported on an argument. **Options considered:** - *Defer the baseline commit until a later signal confirms the compile.* Rejected: inside the generator there is no such signal. The next run's input compilation never contains the previous output, and nothing tells the generator whether the emit or EnC apply succeeded. - *Count all semantic errors.* Rejected: false rollbacks for MVVM Toolkit members. A false positive is worse than a miss, because the next patch re-adds children that are already live. - *Restrict to diagnostics attributable to XAML-generated code and filter out what another generator could fix.* Chosen. **Known remaining gap:** a lookup on a non-`partial` or metadata type (e.g. `int`) that only an extension method from *another generator* could satisfy still counts as an error. That's rare in XAML expressions. C# 14 extension members generated elsewhere fall in the same case. `XamlHotReloadState` is unchanged. The change is limited to `XamlGenerator.cs`, to keep conflicts with the #40233 follow-up low. **Tests** (`XamlIncrementalHotReloadRudeEditTests`): - `EditAfterRudeEdit_IsDiffedAgainstLastAppliedGeneration(Semantic)`: new case for a type-check-only rude edit, `{Count.Nope()}`. The theory parameter changed from `bool` to a `RudeEdit` enum. - `ElementAddedWithSemanticRudeEdit_IsAddedOnceTheEditIsFixed`: an element added together with a semantic rude edit is added once the edit is fixed. - `MembersGeneratedByAnotherGenerator_DoNotRollBack`: guard. The view model uses `[ObservableProperty]` and `[RelayCommand]`, and the XAML references `Count` (C# expression) and `{Binding SaveCommand}`. The previous edit must not be rolled back, so the added `Button` isn't added again. Without the fix, the 2 semantic cases fail. With `MayBeFixedByAnotherGenerator` disabled, the guard fails. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter FullyQualifiedName~XamlIncrementalHotReloadRudeEditTests`: **9 passed**. Before the fix: 2 failed (the semantic cases), 7 passed. With the filter disabled: 1 failed (the MVVM guard). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` (full suite): **772 passed, 0 failed, 53 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj` with `-p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false`. The mobile TFMs were excluded because of a local workload mismatch. Result: **2250 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) are known and depend on the machine's locale. - `dotnet format whitespace --folder --include <changed files> --verify-no-changes`: clean. ### Issues Fixed Follow-up to #40235. Relates to #36156. <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
…ns (#40378) <!-- 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! ### 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). > [!IMPORTANT] > **Base: `candidate/11.0.1xx-sr2` (decided).** This PR builds on #40233, #40235, #40329 and #40330, which exist only on `candidate/11.0.1xx-sr2` (not on `net11`, `main` or `inflight/11.0.1xx-sr3`). Against `net11` the diff would include about 527 unrelated files. As with #40329 and #40330, it targets `candidate/11.0.1xx-sr2` directly so it ships together with its prerequisites. ### Description of Change #40330 left one limitation. A throwaway generator run with different XAML, such as a design-time or speculative run whose output never reaches the app, advanced the cached previous XAML. The next real `UpdateComponent()` was then diffed from that intermediate generation instead of the generation the running app actually has. The result was missed edits: for example, an edit already present in the throwaway XAML was never applied. The generator cannot tell which of its runs reached the app, so this PR has `UpdateComponent()` decide at runtime: - **Generation key.** Each successful generation gets a key: a SHA-256 of the normalized XAML plus the node IDs (`NodeIdHelper.ComputeGenerationKey`). `XamlHotReloadState` keeps the current generation and the previously generated ones as baselines, up to `MaxBaselines = 4`. - **InitializeComponent** records `XamlComponentRegistry.Register(this, "__xihr_generation:<type>", key)`. - **UpdateComponent** reads the instance's recorded key: - A retained generation whose diff produces exactly the current node IDs gets its own branch: the patch diffed from that generation. - Anything else gets the default patch, diffed from the last generated XAML. This matches the previous behavior. - Every patched instance then records the new key, so running the patch again, or for a C#-only edit, changes nothing. - When there is nothing to patch, the output is unchanged: an empty UC, with no marker. Rude-edit rollback behavior is preserved, and the older applied generation now also gets its own branch. **Known edge, not a regression:** a retained generation whose diff would assign different IDs from the current ones (e.g. some reverts) is not given a branch. Instances at that generation fall back to the default patch, which is the old behavior. ### Issues Fixed Fixes #36937 (remaining limitation from #40330) ### Tests - `XamlIncrementalHotReloadE2ETests.ThrowawayRunWithDifferentXaml_PatchStartsFromTheAppliedGeneration`: real metadata update. Applied `Text="Hello"`, then a throwaway run with `Text="World" FontSize="30"`, then the real edit to `Text="World"`. The live label ends at `World` with its default `FontSize`, re-running UC is a no-op, and new instances are already current. A new harness hook, `GenerateWithThrowawayRuns`, runs and discards a forked driver run. - `XamlIncrementalHotReloadPipelineTests.ThrowawayRunWithDifferentXaml_PatchesFromEveryRetainedGeneration`: checks the branch structure and determinism (same snapshot and C#-only edits give an identical UC). - `XamlIncrementalHotReloadPipelineTests.RetainedGenerations_AreBounded` - Existing rude-edit assertions now target the default patch (`UpdateComponentText.DefaultPatch`), because the UC legitimately contains a branch for the older applied generation. ### Validation - `DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: **passed**, 899/899. - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~HotReload"`: **passed**, 12/12. - `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2274 passed, 12 failed. All 12 failures are `CultureNotFoundException` from culture-specific tests under invariant-globalization mode; none involve hot reload. - `dotnet format whitespace Microsoft.Maui.sln --verify-no-changes --include <changed files>`: **passed**. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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 XAML Incremental Hot Reload (XIHR) keeps per-file state in `XamlHotReloadState` (last XAML, parsed tree, node IDs) and emits `UpdateComponent()` as a diff from the previous generation to the current one. A **rude edit** is a XAML edit whose generated code doesn't compile, for example a malformed XAML C# expression, or an error reported by the generator such as an unresolved member. The build fails, so that edit never reaches the running app. The state had already moved to the broken generation, though. The next, fixed edit was then diffed against the broken generation, not against what the app is running. Changes made together with the rude edit were never applied: property sets, and elements added in the same edit. They stayed lost until a full restart. **Fix:** - Before diffing a XAML edit, the generator captures a copy of the file's state entry (`XamlHotReloadState.Capture`). - After generating `InitializeComponent` and `UpdateComponent`, it restores that entry (`XamlHotReloadState.Restore`) when the generation can't build: - the generator reported an error while generating `InitializeComponent`. A new optional `diagnosticObserver` on `GenerateInitializeComponent` reports these. User severity overrides are honored (`NoWarn`, `WarningsNotAsErrors`, `.editorconfig`/`.globalconfig`), so a downgraded MAUIX error doesn't count; - or the generated IC/UC code has C# **syntax** errors; - or generation throws. - The next edit is then diffed against the last generation that could have been applied. Its patch also carries the changes made together with the rude edit. Re-evaluating the rude edit is deterministic, and reverting to the applied XAML is "no change". **Deliberately not checked: semantic C# errors** in the generated code, such as `{Count.Nope()}` (CS1061). Generated code can legitimately reference members that other generators add later, such as CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`, which `ITypeSymbolExtensions` already infers. A false positive is worse than a miss: it pins the state to a generation the app has already moved past, and the next patch would re-add children, for example. Those edits keep today's behavior. A C#-only compile failure that happens at the same time as a XAML edit is also out of scope. **Interaction with #40233 (fix for #36937):** The two are independent, so this PR is not stacked on #40233. #40233 adds `PatchBaseline`/`PatchSources` to `CacheEntry` and replays the pending patch when the same inputs are evaluated again. This PR snapshots and restores the whole `CacheEntry` with `MemberwiseClone`, so after a rebase, rolling back a rude edit also restores those fields. The restored state is exactly what the applied generation left, so the output for identical inputs stays identical. Expected conflicts are textual only, in `XamlGenerator.cs` (adjacent lines in the IC output callback) and `XamlHotReloadState.cs`. The new tests are in their own file to avoid conflicts in `XamlIncrementalHotReloadPipelineTests.cs`. **Tests:** new `XamlIncrementalHotReloadRudeEditTests` (6 cases): - an edit after a rude edit carries the changes made with the rude edit, for both a C# syntax error and a generator-reported error (MAUIX2009); - an element added with a rude edit is added once the edit is fixed; - reverting after a rude edit emits the same output as the applied state; - repeated evaluation of a rude edit is deterministic; - an error the user downgraded doesn't roll back (no duplicate element). The first 5 cases fail without the fix. The downgrade case fails if the severity lookup is removed. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter XamlIncrementalHotReloadRudeEditTests`: 6 passed; 5 failed before the fix. - SourceGen.UnitTests, full suite. It was run from a copy of the output in a path without `~`, because the `XTypeMultiFileHotReloadTests` fail when the path contains `~`. Result: **634 passed, 0 failed, 40 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`, built with Apple/Android TFMs excluded because of a local workload mismatch. Result: **2179 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) depend on the dev machine's locale (comma decimal separator) and pass with `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1`. - `dotnet format whitespace --verify-no-changes` on the changed files: clean. ### Issues Fixed Fixes #36156 <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
<!-- 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). This PR targets `candidate/11.0.1xx-sr2`, not `net11`. It's a follow-up to #40235, which was merged into `candidate/11.0.1xx-sr2` and isn't in `net11` (or `main`) yet. The change builds on the code #40235 added. 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 Follow-up to #40235 (fix for #36156). #40235 rolls back the XAML Incremental Hot Reload state (`XamlHotReloadState.Restore`) when a XAML edit can't build. It checks three things: the generator reported an error, the generated IC/UC has C# **syntax** errors, or generation threw. It deliberately skipped **semantic** errors. Members added by other generators (CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`) aren't visible to the XAML generator, so a naive type check would roll back valid edits. As a result, an edit that only fails type checking, such as `{Count.Nope()}` (CS1061), still advanced the baseline. The next valid edit was then diffed against a generation the app never received, and the changes made together with the rude edit were lost. **Fix:** `HasSemanticErrors` type-checks the generated `InitializeComponent` and `UpdateComponent` trees against the generator's compilation (user code plus generated code-behind). It runs only when a XAML edit was diffed, i.e. when a rollback snapshot exists. An error counts only if: - it is located in the generated IC/UC code (errors in user code are ignored), and - `MayBeFixedByAnotherGenerator` returns false for it. That helper ignores errors that a declaration added by another generator could resolve: - unresolved names, types and namespaces (CS0103, CS0234, CS0246, CS0426); - failed member lookup (CS1061, CS0117, …) or overload resolution on a receiver whose type is a **`partial` type declared in source**, the only kind of type other generators can add members to. This also covers `?.` member bindings, implicit-`this` invocations, object creations, and errors reported on an argument. **Options considered:** - *Defer the baseline commit until a later signal confirms the compile.* Rejected: inside the generator there is no such signal. The next run's input compilation never contains the previous output, and nothing tells the generator whether the emit or EnC apply succeeded. - *Count all semantic errors.* Rejected: false rollbacks for MVVM Toolkit members. A false positive is worse than a miss, because the next patch re-adds children that are already live. - *Restrict to diagnostics attributable to XAML-generated code and filter out what another generator could fix.* Chosen. **Known remaining gap:** a lookup on a non-`partial` or metadata type (e.g. `int`) that only an extension method from *another generator* could satisfy still counts as an error. That's rare in XAML expressions. C# 14 extension members generated elsewhere fall in the same case. `XamlHotReloadState` is unchanged. The change is limited to `XamlGenerator.cs`, to keep conflicts with the #40233 follow-up low. **Tests** (`XamlIncrementalHotReloadRudeEditTests`): - `EditAfterRudeEdit_IsDiffedAgainstLastAppliedGeneration(Semantic)`: new case for a type-check-only rude edit, `{Count.Nope()}`. The theory parameter changed from `bool` to a `RudeEdit` enum. - `ElementAddedWithSemanticRudeEdit_IsAddedOnceTheEditIsFixed`: an element added together with a semantic rude edit is added once the edit is fixed. - `MembersGeneratedByAnotherGenerator_DoNotRollBack`: guard. The view model uses `[ObservableProperty]` and `[RelayCommand]`, and the XAML references `Count` (C# expression) and `{Binding SaveCommand}`. The previous edit must not be rolled back, so the added `Button` isn't added again. Without the fix, the 2 semantic cases fail. With `MayBeFixedByAnotherGenerator` disabled, the guard fails. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter FullyQualifiedName~XamlIncrementalHotReloadRudeEditTests`: **9 passed**. Before the fix: 2 failed (the semantic cases), 7 passed. With the filter disabled: 1 failed (the MVVM guard). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` (full suite): **772 passed, 0 failed, 53 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj` with `-p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false`. The mobile TFMs were excluded because of a local workload mismatch. Result: **2250 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) are known and depend on the machine's locale. - `dotnet format whitespace --folder --include <changed files> --verify-no-changes`: clean. ### Issues Fixed Follow-up to #40235. Relates to #36156. <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
…ns (#40378) <!-- 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! ### 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). > [!IMPORTANT] > **Base: `candidate/11.0.1xx-sr2` (decided).** This PR builds on #40233, #40235, #40329 and #40330, which exist only on `candidate/11.0.1xx-sr2` (not on `net11`, `main` or `inflight/11.0.1xx-sr3`). Against `net11` the diff would include about 527 unrelated files. As with #40329 and #40330, it targets `candidate/11.0.1xx-sr2` directly so it ships together with its prerequisites. ### Description of Change #40330 left one limitation. A throwaway generator run with different XAML, such as a design-time or speculative run whose output never reaches the app, advanced the cached previous XAML. The next real `UpdateComponent()` was then diffed from that intermediate generation instead of the generation the running app actually has. The result was missed edits: for example, an edit already present in the throwaway XAML was never applied. The generator cannot tell which of its runs reached the app, so this PR has `UpdateComponent()` decide at runtime: - **Generation key.** Each successful generation gets a key: a SHA-256 of the normalized XAML plus the node IDs (`NodeIdHelper.ComputeGenerationKey`). `XamlHotReloadState` keeps the current generation and the previously generated ones as baselines, up to `MaxBaselines = 4`. - **InitializeComponent** records `XamlComponentRegistry.Register(this, "__xihr_generation:<type>", key)`. - **UpdateComponent** reads the instance's recorded key: - A retained generation whose diff produces exactly the current node IDs gets its own branch: the patch diffed from that generation. - Anything else gets the default patch, diffed from the last generated XAML. This matches the previous behavior. - Every patched instance then records the new key, so running the patch again, or for a C#-only edit, changes nothing. - When there is nothing to patch, the output is unchanged: an empty UC, with no marker. Rude-edit rollback behavior is preserved, and the older applied generation now also gets its own branch. **Known edge, not a regression:** a retained generation whose diff would assign different IDs from the current ones (e.g. some reverts) is not given a branch. Instances at that generation fall back to the default patch, which is the old behavior. ### Issues Fixed Fixes #36937 (remaining limitation from #40330) ### Tests - `XamlIncrementalHotReloadE2ETests.ThrowawayRunWithDifferentXaml_PatchStartsFromTheAppliedGeneration`: real metadata update. Applied `Text="Hello"`, then a throwaway run with `Text="World" FontSize="30"`, then the real edit to `Text="World"`. The live label ends at `World` with its default `FontSize`, re-running UC is a no-op, and new instances are already current. A new harness hook, `GenerateWithThrowawayRuns`, runs and discards a forked driver run. - `XamlIncrementalHotReloadPipelineTests.ThrowawayRunWithDifferentXaml_PatchesFromEveryRetainedGeneration`: checks the branch structure and determinism (same snapshot and C#-only edits give an identical UC). - `XamlIncrementalHotReloadPipelineTests.RetainedGenerations_AreBounded` - Existing rude-edit assertions now target the default patch (`UpdateComponentText.DefaultPatch`), because the UC legitimately contains a branch for the older applied generation. ### Validation - `DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: **passed**, 899/899. - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~HotReload"`: **passed**, 12/12. - `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2274 passed, 12 failed. All 12 failures are `CultureNotFoundException` from culture-specific tests under invariant-globalization mode; none involve hot reload. - `dotnet format whitespace Microsoft.Maui.sln --verify-no-changes --include <changed files>`: **passed**. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…40413) (#40417) <!-- 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). **Base is `candidate/11.0.1xx-sr2`, not `net11`.** The PR is test-only and covers behavior that exists only on the candidate branch, from the #36937 fix chain #40233, #40235, #40329, #40330, and #40378. Against `net11` the test fails, because that fix has not flowed there yet. This follows the precedent of #40329, #40330, and #40378, which targeted this branch for the same reason. Maintainers: retarget if you prefer a different lane. 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 #40413 reports that in VS on Windows (.NET 11, SourceGen inflator, XAML Incremental Hot Reload on by default in Debug), editing a Label's `Text` in the default template's `MainPage.xaml` is not applied. **Root cause.** This is #36937. Roslyn/VS evaluate the same edited generator-driver snapshot more than once, for example forked or speculative runs, or a throwaway compilation before the applied one. On `net11`, the first evaluation advances the cached previous XAML. The evaluation that is actually applied then sees no diff and emits an empty `UpdateComponent`, and the runtime silently skips it. The bug became visible in .NET 11 because XIHR is now the default; 10.0.120 used legacy XAML Hot Reload. I reproduced this with the issue's own template `MainPage.xaml` through the source generator: | Sequence | `net11` (a25e629) | `candidate/11.0.1xx-sr2` (cec6650) | | --- | --- | --- | | Edit evaluated once | patch | patch | | Same edited snapshot evaluated twice: 2nd run | **empty UC** | patch | | Throwaway compilation first, then real run: real run | **empty UC** | patch | On the candidate branch the existing fixes already handle this. This PR adds `DefaultTemplateMainPageTextEdit_SurvivesRepeatedAndThrowawayEvaluations`, a theory with repeated and throwaway-first cases. It uses the template page shape (`StaticResource` styles from a sibling `Styles.xaml`, `x:Name`, a `Clicked` handler in code-behind) to lock in the reported scenario. There are no product changes. **Android .NET 10 (validation comment).** This is a separate scenario. XIHR was not the default in .NET 10, so that report involves the legacy XAML Hot Reload path and is not caused by this regression. It is not addressed here. **Validation** - `DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter "FullyQualifiedName~XamlIncrementalHotReloadPipelineTests|FullyQualifiedName~CodeBehindFieldStabilityTests"`: **passed**, 93/93, on this branch. - `net11`: the same two sequences, run through an equivalent temporary probe with the template XAML, produce an empty UC, as shown in the table. I did not port the committed test itself to `net11`: its helpers exist only on candidate, and reverting the fix commits in place conflicts. - Not verified in Visual Studio on Windows or on device; I worked on a macOS host. ### Issues Fixed Fixes #40413 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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 XAML Incremental Hot Reload (XIHR) keeps per-file state in `XamlHotReloadState` (last XAML, parsed tree, node IDs) and emits `UpdateComponent()` as a diff from the previous generation to the current one. A **rude edit** is a XAML edit whose generated code doesn't compile, for example a malformed XAML C# expression, or an error reported by the generator such as an unresolved member. The build fails, so that edit never reaches the running app. The state had already moved to the broken generation, though. The next, fixed edit was then diffed against the broken generation, not against what the app is running. Changes made together with the rude edit were never applied: property sets, and elements added in the same edit. They stayed lost until a full restart. **Fix:** - Before diffing a XAML edit, the generator captures a copy of the file's state entry (`XamlHotReloadState.Capture`). - After generating `InitializeComponent` and `UpdateComponent`, it restores that entry (`XamlHotReloadState.Restore`) when the generation can't build: - the generator reported an error while generating `InitializeComponent`. A new optional `diagnosticObserver` on `GenerateInitializeComponent` reports these. User severity overrides are honored (`NoWarn`, `WarningsNotAsErrors`, `.editorconfig`/`.globalconfig`), so a downgraded MAUIX error doesn't count; - or the generated IC/UC code has C# **syntax** errors; - or generation throws. - The next edit is then diffed against the last generation that could have been applied. Its patch also carries the changes made together with the rude edit. Re-evaluating the rude edit is deterministic, and reverting to the applied XAML is "no change". **Deliberately not checked: semantic C# errors** in the generated code, such as `{Count.Nope()}` (CS1061). Generated code can legitimately reference members that other generators add later, such as CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`, which `ITypeSymbolExtensions` already infers. A false positive is worse than a miss: it pins the state to a generation the app has already moved past, and the next patch would re-add children, for example. Those edits keep today's behavior. A C#-only compile failure that happens at the same time as a XAML edit is also out of scope. **Interaction with #40233 (fix for #36937):** The two are independent, so this PR is not stacked on #40233. #40233 adds `PatchBaseline`/`PatchSources` to `CacheEntry` and replays the pending patch when the same inputs are evaluated again. This PR snapshots and restores the whole `CacheEntry` with `MemberwiseClone`, so after a rebase, rolling back a rude edit also restores those fields. The restored state is exactly what the applied generation left, so the output for identical inputs stays identical. Expected conflicts are textual only, in `XamlGenerator.cs` (adjacent lines in the IC output callback) and `XamlHotReloadState.cs`. The new tests are in their own file to avoid conflicts in `XamlIncrementalHotReloadPipelineTests.cs`. **Tests:** new `XamlIncrementalHotReloadRudeEditTests` (6 cases): - an edit after a rude edit carries the changes made with the rude edit, for both a C# syntax error and a generator-reported error (MAUIX2009); - an element added with a rude edit is added once the edit is fixed; - reverting after a rude edit emits the same output as the applied state; - repeated evaluation of a rude edit is deterministic; - an error the user downgraded doesn't roll back (no duplicate element). The first 5 cases fail without the fix. The downgrade case fails if the severity lookup is removed. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter XamlIncrementalHotReloadRudeEditTests`: 6 passed; 5 failed before the fix. - SourceGen.UnitTests, full suite. It was run from a copy of the output in a path without `~`, because the `XTypeMultiFileHotReloadTests` fail when the path contains `~`. Result: **634 passed, 0 failed, 40 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`, built with Apple/Android TFMs excluded because of a local workload mismatch. Result: **2179 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) depend on the dev machine's locale (comma decimal separator) and pass with `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1`. - `dotnet format whitespace --verify-no-changes` on the changed files: clean. ### Issues Fixed Fixes #36156 <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
<!-- 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). This PR targets `candidate/11.0.1xx-sr2`, not `net11`. It's a follow-up to #40235, which was merged into `candidate/11.0.1xx-sr2` and isn't in `net11` (or `main`) yet. The change builds on the code #40235 added. 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 Follow-up to #40235 (fix for #36156). #40235 rolls back the XAML Incremental Hot Reload state (`XamlHotReloadState.Restore`) when a XAML edit can't build. It checks three things: the generator reported an error, the generated IC/UC has C# **syntax** errors, or generation threw. It deliberately skipped **semantic** errors. Members added by other generators (CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`) aren't visible to the XAML generator, so a naive type check would roll back valid edits. As a result, an edit that only fails type checking, such as `{Count.Nope()}` (CS1061), still advanced the baseline. The next valid edit was then diffed against a generation the app never received, and the changes made together with the rude edit were lost. **Fix:** `HasSemanticErrors` type-checks the generated `InitializeComponent` and `UpdateComponent` trees against the generator's compilation (user code plus generated code-behind). It runs only when a XAML edit was diffed, i.e. when a rollback snapshot exists. An error counts only if: - it is located in the generated IC/UC code (errors in user code are ignored), and - `MayBeFixedByAnotherGenerator` returns false for it. That helper ignores errors that a declaration added by another generator could resolve: - unresolved names, types and namespaces (CS0103, CS0234, CS0246, CS0426); - failed member lookup (CS1061, CS0117, …) or overload resolution on a receiver whose type is a **`partial` type declared in source**, the only kind of type other generators can add members to. This also covers `?.` member bindings, implicit-`this` invocations, object creations, and errors reported on an argument. **Options considered:** - *Defer the baseline commit until a later signal confirms the compile.* Rejected: inside the generator there is no such signal. The next run's input compilation never contains the previous output, and nothing tells the generator whether the emit or EnC apply succeeded. - *Count all semantic errors.* Rejected: false rollbacks for MVVM Toolkit members. A false positive is worse than a miss, because the next patch re-adds children that are already live. - *Restrict to diagnostics attributable to XAML-generated code and filter out what another generator could fix.* Chosen. **Known remaining gap:** a lookup on a non-`partial` or metadata type (e.g. `int`) that only an extension method from *another generator* could satisfy still counts as an error. That's rare in XAML expressions. C# 14 extension members generated elsewhere fall in the same case. `XamlHotReloadState` is unchanged. The change is limited to `XamlGenerator.cs`, to keep conflicts with the #40233 follow-up low. **Tests** (`XamlIncrementalHotReloadRudeEditTests`): - `EditAfterRudeEdit_IsDiffedAgainstLastAppliedGeneration(Semantic)`: new case for a type-check-only rude edit, `{Count.Nope()}`. The theory parameter changed from `bool` to a `RudeEdit` enum. - `ElementAddedWithSemanticRudeEdit_IsAddedOnceTheEditIsFixed`: an element added together with a semantic rude edit is added once the edit is fixed. - `MembersGeneratedByAnotherGenerator_DoNotRollBack`: guard. The view model uses `[ObservableProperty]` and `[RelayCommand]`, and the XAML references `Count` (C# expression) and `{Binding SaveCommand}`. The previous edit must not be rolled back, so the added `Button` isn't added again. Without the fix, the 2 semantic cases fail. With `MayBeFixedByAnotherGenerator` disabled, the guard fails. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter FullyQualifiedName~XamlIncrementalHotReloadRudeEditTests`: **9 passed**. Before the fix: 2 failed (the semantic cases), 7 passed. With the filter disabled: 1 failed (the MVVM guard). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` (full suite): **772 passed, 0 failed, 53 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj` with `-p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false`. The mobile TFMs were excluded because of a local workload mismatch. Result: **2250 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) are known and depend on the machine's locale. - `dotnet format whitespace --folder --include <changed files> --verify-no-changes`: clean. ### Issues Fixed Follow-up to #40235. Relates to #36156. <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
…ns (#40378) <!-- 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! ### 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). > [!IMPORTANT] > **Base: `candidate/11.0.1xx-sr2` (decided).** This PR builds on #40233, #40235, #40329 and #40330, which exist only on `candidate/11.0.1xx-sr2` (not on `net11`, `main` or `inflight/11.0.1xx-sr3`). Against `net11` the diff would include about 527 unrelated files. As with #40329 and #40330, it targets `candidate/11.0.1xx-sr2` directly so it ships together with its prerequisites. ### Description of Change #40330 left one limitation. A throwaway generator run with different XAML, such as a design-time or speculative run whose output never reaches the app, advanced the cached previous XAML. The next real `UpdateComponent()` was then diffed from that intermediate generation instead of the generation the running app actually has. The result was missed edits: for example, an edit already present in the throwaway XAML was never applied. The generator cannot tell which of its runs reached the app, so this PR has `UpdateComponent()` decide at runtime: - **Generation key.** Each successful generation gets a key: a SHA-256 of the normalized XAML plus the node IDs (`NodeIdHelper.ComputeGenerationKey`). `XamlHotReloadState` keeps the current generation and the previously generated ones as baselines, up to `MaxBaselines = 4`. - **InitializeComponent** records `XamlComponentRegistry.Register(this, "__xihr_generation:<type>", key)`. - **UpdateComponent** reads the instance's recorded key: - A retained generation whose diff produces exactly the current node IDs gets its own branch: the patch diffed from that generation. - Anything else gets the default patch, diffed from the last generated XAML. This matches the previous behavior. - Every patched instance then records the new key, so running the patch again, or for a C#-only edit, changes nothing. - When there is nothing to patch, the output is unchanged: an empty UC, with no marker. Rude-edit rollback behavior is preserved, and the older applied generation now also gets its own branch. **Known edge, not a regression:** a retained generation whose diff would assign different IDs from the current ones (e.g. some reverts) is not given a branch. Instances at that generation fall back to the default patch, which is the old behavior. ### Issues Fixed Fixes #36937 (remaining limitation from #40330) ### Tests - `XamlIncrementalHotReloadE2ETests.ThrowawayRunWithDifferentXaml_PatchStartsFromTheAppliedGeneration`: real metadata update. Applied `Text="Hello"`, then a throwaway run with `Text="World" FontSize="30"`, then the real edit to `Text="World"`. The live label ends at `World` with its default `FontSize`, re-running UC is a no-op, and new instances are already current. A new harness hook, `GenerateWithThrowawayRuns`, runs and discards a forked driver run. - `XamlIncrementalHotReloadPipelineTests.ThrowawayRunWithDifferentXaml_PatchesFromEveryRetainedGeneration`: checks the branch structure and determinism (same snapshot and C#-only edits give an identical UC). - `XamlIncrementalHotReloadPipelineTests.RetainedGenerations_AreBounded` - Existing rude-edit assertions now target the default patch (`UpdateComponentText.DefaultPatch`), because the UC legitimately contains a branch for the older applied generation. ### Validation - `DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: **passed**, 899/899. - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~HotReload"`: **passed**, 12/12. - `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2274 passed, 12 failed. All 12 failures are `CultureNotFoundException` from culture-specific tests under invariant-globalization mode; none involve hot reload. - `dotnet format whitespace Microsoft.Maui.sln --verify-no-changes --include <changed files>`: **passed**. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…40413) (#40417) <!-- 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). **Base is `candidate/11.0.1xx-sr2`, not `net11`.** The PR is test-only and covers behavior that exists only on the candidate branch, from the #36937 fix chain #40233, #40235, #40329, #40330, and #40378. Against `net11` the test fails, because that fix has not flowed there yet. This follows the precedent of #40329, #40330, and #40378, which targeted this branch for the same reason. Maintainers: retarget if you prefer a different lane. 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 #40413 reports that in VS on Windows (.NET 11, SourceGen inflator, XAML Incremental Hot Reload on by default in Debug), editing a Label's `Text` in the default template's `MainPage.xaml` is not applied. **Root cause.** This is #36937. Roslyn/VS evaluate the same edited generator-driver snapshot more than once, for example forked or speculative runs, or a throwaway compilation before the applied one. On `net11`, the first evaluation advances the cached previous XAML. The evaluation that is actually applied then sees no diff and emits an empty `UpdateComponent`, and the runtime silently skips it. The bug became visible in .NET 11 because XIHR is now the default; 10.0.120 used legacy XAML Hot Reload. I reproduced this with the issue's own template `MainPage.xaml` through the source generator: | Sequence | `net11` (a25e629) | `candidate/11.0.1xx-sr2` (cec6650) | | --- | --- | --- | | Edit evaluated once | patch | patch | | Same edited snapshot evaluated twice: 2nd run | **empty UC** | patch | | Throwaway compilation first, then real run: real run | **empty UC** | patch | On the candidate branch the existing fixes already handle this. This PR adds `DefaultTemplateMainPageTextEdit_SurvivesRepeatedAndThrowawayEvaluations`, a theory with repeated and throwaway-first cases. It uses the template page shape (`StaticResource` styles from a sibling `Styles.xaml`, `x:Name`, a `Clicked` handler in code-behind) to lock in the reported scenario. There are no product changes. **Android .NET 10 (validation comment).** This is a separate scenario. XIHR was not the default in .NET 10, so that report involves the legacy XAML Hot Reload path and is not caused by this regression. It is not addressed here. **Validation** - `DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter "FullyQualifiedName~XamlIncrementalHotReloadPipelineTests|FullyQualifiedName~CodeBehindFieldStabilityTests"`: **passed**, 93/93, on this branch. - `net11`: the same two sequences, run through an equivalent temporary probe with the template XAML, produce an empty UC, as shown in the table. I did not port the committed test itself to `net11`: its helpers exist only on candidate, and reverting the fix commits in place conflicts. - Not verified in Visual Studio on Windows or on device; I worked on a macOS host. ### Issues Fixed Fixes #40413 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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 XAML Incremental Hot Reload (XIHR) keeps per-file state in `XamlHotReloadState` (last XAML, parsed tree, node IDs) and emits `UpdateComponent()` as a diff from the previous generation to the current one. A **rude edit** is a XAML edit whose generated code doesn't compile, for example a malformed XAML C# expression, or an error reported by the generator such as an unresolved member. The build fails, so that edit never reaches the running app. The state had already moved to the broken generation, though. The next, fixed edit was then diffed against the broken generation, not against what the app is running. Changes made together with the rude edit were never applied: property sets, and elements added in the same edit. They stayed lost until a full restart. **Fix:** - Before diffing a XAML edit, the generator captures a copy of the file's state entry (`XamlHotReloadState.Capture`). - After generating `InitializeComponent` and `UpdateComponent`, it restores that entry (`XamlHotReloadState.Restore`) when the generation can't build: - the generator reported an error while generating `InitializeComponent`. A new optional `diagnosticObserver` on `GenerateInitializeComponent` reports these. User severity overrides are honored (`NoWarn`, `WarningsNotAsErrors`, `.editorconfig`/`.globalconfig`), so a downgraded MAUIX error doesn't count; - or the generated IC/UC code has C# **syntax** errors; - or generation throws. - The next edit is then diffed against the last generation that could have been applied. Its patch also carries the changes made together with the rude edit. Re-evaluating the rude edit is deterministic, and reverting to the applied XAML is "no change". **Deliberately not checked: semantic C# errors** in the generated code, such as `{Count.Nope()}` (CS1061). Generated code can legitimately reference members that other generators add later, such as CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`, which `ITypeSymbolExtensions` already infers. A false positive is worse than a miss: it pins the state to a generation the app has already moved past, and the next patch would re-add children, for example. Those edits keep today's behavior. A C#-only compile failure that happens at the same time as a XAML edit is also out of scope. **Interaction with #40233 (fix for #36937):** The two are independent, so this PR is not stacked on #40233. #40233 adds `PatchBaseline`/`PatchSources` to `CacheEntry` and replays the pending patch when the same inputs are evaluated again. This PR snapshots and restores the whole `CacheEntry` with `MemberwiseClone`, so after a rebase, rolling back a rude edit also restores those fields. The restored state is exactly what the applied generation left, so the output for identical inputs stays identical. Expected conflicts are textual only, in `XamlGenerator.cs` (adjacent lines in the IC output callback) and `XamlHotReloadState.cs`. The new tests are in their own file to avoid conflicts in `XamlIncrementalHotReloadPipelineTests.cs`. **Tests:** new `XamlIncrementalHotReloadRudeEditTests` (6 cases): - an edit after a rude edit carries the changes made with the rude edit, for both a C# syntax error and a generator-reported error (MAUIX2009); - an element added with a rude edit is added once the edit is fixed; - reverting after a rude edit emits the same output as the applied state; - repeated evaluation of a rude edit is deterministic; - an error the user downgraded doesn't roll back (no duplicate element). The first 5 cases fail without the fix. The downgrade case fails if the severity lookup is removed. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter XamlIncrementalHotReloadRudeEditTests`: 6 passed; 5 failed before the fix. - SourceGen.UnitTests, full suite. It was run from a copy of the output in a path without `~`, because the `XTypeMultiFileHotReloadTests` fail when the path contains `~`. Result: **634 passed, 0 failed, 40 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`, built with Apple/Android TFMs excluded because of a local workload mismatch. Result: **2179 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) depend on the dev machine's locale (comma decimal separator) and pass with `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1`. - `dotnet format whitespace --verify-no-changes` on the changed files: clean. ### Issues Fixed Fixes #36156 <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
<!-- 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). This PR targets `candidate/11.0.1xx-sr2`, not `net11`. It's a follow-up to #40235, which was merged into `candidate/11.0.1xx-sr2` and isn't in `net11` (or `main`) yet. The change builds on the code #40235 added. 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 Follow-up to #40235 (fix for #36156). #40235 rolls back the XAML Incremental Hot Reload state (`XamlHotReloadState.Restore`) when a XAML edit can't build. It checks three things: the generator reported an error, the generated IC/UC has C# **syntax** errors, or generation threw. It deliberately skipped **semantic** errors. Members added by other generators (CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`) aren't visible to the XAML generator, so a naive type check would roll back valid edits. As a result, an edit that only fails type checking, such as `{Count.Nope()}` (CS1061), still advanced the baseline. The next valid edit was then diffed against a generation the app never received, and the changes made together with the rude edit were lost. **Fix:** `HasSemanticErrors` type-checks the generated `InitializeComponent` and `UpdateComponent` trees against the generator's compilation (user code plus generated code-behind). It runs only when a XAML edit was diffed, i.e. when a rollback snapshot exists. An error counts only if: - it is located in the generated IC/UC code (errors in user code are ignored), and - `MayBeFixedByAnotherGenerator` returns false for it. That helper ignores errors that a declaration added by another generator could resolve: - unresolved names, types and namespaces (CS0103, CS0234, CS0246, CS0426); - failed member lookup (CS1061, CS0117, …) or overload resolution on a receiver whose type is a **`partial` type declared in source**, the only kind of type other generators can add members to. This also covers `?.` member bindings, implicit-`this` invocations, object creations, and errors reported on an argument. **Options considered:** - *Defer the baseline commit until a later signal confirms the compile.* Rejected: inside the generator there is no such signal. The next run's input compilation never contains the previous output, and nothing tells the generator whether the emit or EnC apply succeeded. - *Count all semantic errors.* Rejected: false rollbacks for MVVM Toolkit members. A false positive is worse than a miss, because the next patch re-adds children that are already live. - *Restrict to diagnostics attributable to XAML-generated code and filter out what another generator could fix.* Chosen. **Known remaining gap:** a lookup on a non-`partial` or metadata type (e.g. `int`) that only an extension method from *another generator* could satisfy still counts as an error. That's rare in XAML expressions. C# 14 extension members generated elsewhere fall in the same case. `XamlHotReloadState` is unchanged. The change is limited to `XamlGenerator.cs`, to keep conflicts with the #40233 follow-up low. **Tests** (`XamlIncrementalHotReloadRudeEditTests`): - `EditAfterRudeEdit_IsDiffedAgainstLastAppliedGeneration(Semantic)`: new case for a type-check-only rude edit, `{Count.Nope()}`. The theory parameter changed from `bool` to a `RudeEdit` enum. - `ElementAddedWithSemanticRudeEdit_IsAddedOnceTheEditIsFixed`: an element added together with a semantic rude edit is added once the edit is fixed. - `MembersGeneratedByAnotherGenerator_DoNotRollBack`: guard. The view model uses `[ObservableProperty]` and `[RelayCommand]`, and the XAML references `Count` (C# expression) and `{Binding SaveCommand}`. The previous edit must not be rolled back, so the added `Button` isn't added again. Without the fix, the 2 semantic cases fail. With `MayBeFixedByAnotherGenerator` disabled, the guard fails. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter FullyQualifiedName~XamlIncrementalHotReloadRudeEditTests`: **9 passed**. Before the fix: 2 failed (the semantic cases), 7 passed. With the filter disabled: 1 failed (the MVVM guard). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` (full suite): **772 passed, 0 failed, 53 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj` with `-p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false`. The mobile TFMs were excluded because of a local workload mismatch. Result: **2250 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) are known and depend on the machine's locale. - `dotnet format whitespace --folder --include <changed files> --verify-no-changes`: clean. ### Issues Fixed Follow-up to #40235. Relates to #36156. <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
…ns (#40378) <!-- 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! ### 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). > [!IMPORTANT] > **Base: `candidate/11.0.1xx-sr2` (decided).** This PR builds on #40233, #40235, #40329 and #40330, which exist only on `candidate/11.0.1xx-sr2` (not on `net11`, `main` or `inflight/11.0.1xx-sr3`). Against `net11` the diff would include about 527 unrelated files. As with #40329 and #40330, it targets `candidate/11.0.1xx-sr2` directly so it ships together with its prerequisites. ### Description of Change #40330 left one limitation. A throwaway generator run with different XAML, such as a design-time or speculative run whose output never reaches the app, advanced the cached previous XAML. The next real `UpdateComponent()` was then diffed from that intermediate generation instead of the generation the running app actually has. The result was missed edits: for example, an edit already present in the throwaway XAML was never applied. The generator cannot tell which of its runs reached the app, so this PR has `UpdateComponent()` decide at runtime: - **Generation key.** Each successful generation gets a key: a SHA-256 of the normalized XAML plus the node IDs (`NodeIdHelper.ComputeGenerationKey`). `XamlHotReloadState` keeps the current generation and the previously generated ones as baselines, up to `MaxBaselines = 4`. - **InitializeComponent** records `XamlComponentRegistry.Register(this, "__xihr_generation:<type>", key)`. - **UpdateComponent** reads the instance's recorded key: - A retained generation whose diff produces exactly the current node IDs gets its own branch: the patch diffed from that generation. - Anything else gets the default patch, diffed from the last generated XAML. This matches the previous behavior. - Every patched instance then records the new key, so running the patch again, or for a C#-only edit, changes nothing. - When there is nothing to patch, the output is unchanged: an empty UC, with no marker. Rude-edit rollback behavior is preserved, and the older applied generation now also gets its own branch. **Known edge, not a regression:** a retained generation whose diff would assign different IDs from the current ones (e.g. some reverts) is not given a branch. Instances at that generation fall back to the default patch, which is the old behavior. ### Issues Fixed Fixes #36937 (remaining limitation from #40330) ### Tests - `XamlIncrementalHotReloadE2ETests.ThrowawayRunWithDifferentXaml_PatchStartsFromTheAppliedGeneration`: real metadata update. Applied `Text="Hello"`, then a throwaway run with `Text="World" FontSize="30"`, then the real edit to `Text="World"`. The live label ends at `World` with its default `FontSize`, re-running UC is a no-op, and new instances are already current. A new harness hook, `GenerateWithThrowawayRuns`, runs and discards a forked driver run. - `XamlIncrementalHotReloadPipelineTests.ThrowawayRunWithDifferentXaml_PatchesFromEveryRetainedGeneration`: checks the branch structure and determinism (same snapshot and C#-only edits give an identical UC). - `XamlIncrementalHotReloadPipelineTests.RetainedGenerations_AreBounded` - Existing rude-edit assertions now target the default patch (`UpdateComponentText.DefaultPatch`), because the UC legitimately contains a branch for the older applied generation. ### Validation - `DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: **passed**, 899/899. - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~HotReload"`: **passed**, 12/12. - `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2274 passed, 12 failed. All 12 failures are `CultureNotFoundException` from culture-specific tests under invariant-globalization mode; none involve hot reload. - `dotnet format whitespace Microsoft.Maui.sln --verify-no-changes --include <changed files>`: **passed**. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…40413) (#40417) <!-- 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). **Base is `candidate/11.0.1xx-sr2`, not `net11`.** The PR is test-only and covers behavior that exists only on the candidate branch, from the #36937 fix chain #40233, #40235, #40329, #40330, and #40378. Against `net11` the test fails, because that fix has not flowed there yet. This follows the precedent of #40329, #40330, and #40378, which targeted this branch for the same reason. Maintainers: retarget if you prefer a different lane. 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 #40413 reports that in VS on Windows (.NET 11, SourceGen inflator, XAML Incremental Hot Reload on by default in Debug), editing a Label's `Text` in the default template's `MainPage.xaml` is not applied. **Root cause.** This is #36937. Roslyn/VS evaluate the same edited generator-driver snapshot more than once, for example forked or speculative runs, or a throwaway compilation before the applied one. On `net11`, the first evaluation advances the cached previous XAML. The evaluation that is actually applied then sees no diff and emits an empty `UpdateComponent`, and the runtime silently skips it. The bug became visible in .NET 11 because XIHR is now the default; 10.0.120 used legacy XAML Hot Reload. I reproduced this with the issue's own template `MainPage.xaml` through the source generator: | Sequence | `net11` (a25e629) | `candidate/11.0.1xx-sr2` (cec6650) | | --- | --- | --- | | Edit evaluated once | patch | patch | | Same edited snapshot evaluated twice: 2nd run | **empty UC** | patch | | Throwaway compilation first, then real run: real run | **empty UC** | patch | On the candidate branch the existing fixes already handle this. This PR adds `DefaultTemplateMainPageTextEdit_SurvivesRepeatedAndThrowawayEvaluations`, a theory with repeated and throwaway-first cases. It uses the template page shape (`StaticResource` styles from a sibling `Styles.xaml`, `x:Name`, a `Clicked` handler in code-behind) to lock in the reported scenario. There are no product changes. **Android .NET 10 (validation comment).** This is a separate scenario. XIHR was not the default in .NET 10, so that report involves the legacy XAML Hot Reload path and is not caused by this regression. It is not addressed here. **Validation** - `DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter "FullyQualifiedName~XamlIncrementalHotReloadPipelineTests|FullyQualifiedName~CodeBehindFieldStabilityTests"`: **passed**, 93/93, on this branch. - `net11`: the same two sequences, run through an equivalent temporary probe with the template XAML, produce an empty UC, as shown in the table. I did not port the committed test itself to `net11`: its helpers exist only on candidate, and reverting the fix commits in place conflicts. - Not verified in Visual Studio on Windows or on device; I worked on a macOS host. ### Issues Fixed Fixes #40413 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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 XAML Incremental Hot Reload (XIHR) keeps per-file state in `XamlHotReloadState` (last XAML, parsed tree, node IDs) and emits `UpdateComponent()` as a diff from the previous generation to the current one. A **rude edit** is a XAML edit whose generated code doesn't compile, for example a malformed XAML C# expression, or an error reported by the generator such as an unresolved member. The build fails, so that edit never reaches the running app. The state had already moved to the broken generation, though. The next, fixed edit was then diffed against the broken generation, not against what the app is running. Changes made together with the rude edit were never applied: property sets, and elements added in the same edit. They stayed lost until a full restart. **Fix:** - Before diffing a XAML edit, the generator captures a copy of the file's state entry (`XamlHotReloadState.Capture`). - After generating `InitializeComponent` and `UpdateComponent`, it restores that entry (`XamlHotReloadState.Restore`) when the generation can't build: - the generator reported an error while generating `InitializeComponent`. A new optional `diagnosticObserver` on `GenerateInitializeComponent` reports these. User severity overrides are honored (`NoWarn`, `WarningsNotAsErrors`, `.editorconfig`/`.globalconfig`), so a downgraded MAUIX error doesn't count; - or the generated IC/UC code has C# **syntax** errors; - or generation throws. - The next edit is then diffed against the last generation that could have been applied. Its patch also carries the changes made together with the rude edit. Re-evaluating the rude edit is deterministic, and reverting to the applied XAML is "no change". **Deliberately not checked: semantic C# errors** in the generated code, such as `{Count.Nope()}` (CS1061). Generated code can legitimately reference members that other generators add later, such as CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`, which `ITypeSymbolExtensions` already infers. A false positive is worse than a miss: it pins the state to a generation the app has already moved past, and the next patch would re-add children, for example. Those edits keep today's behavior. A C#-only compile failure that happens at the same time as a XAML edit is also out of scope. **Interaction with #40233 (fix for #36937):** The two are independent, so this PR is not stacked on #40233. #40233 adds `PatchBaseline`/`PatchSources` to `CacheEntry` and replays the pending patch when the same inputs are evaluated again. This PR snapshots and restores the whole `CacheEntry` with `MemberwiseClone`, so after a rebase, rolling back a rude edit also restores those fields. The restored state is exactly what the applied generation left, so the output for identical inputs stays identical. Expected conflicts are textual only, in `XamlGenerator.cs` (adjacent lines in the IC output callback) and `XamlHotReloadState.cs`. The new tests are in their own file to avoid conflicts in `XamlIncrementalHotReloadPipelineTests.cs`. **Tests:** new `XamlIncrementalHotReloadRudeEditTests` (6 cases): - an edit after a rude edit carries the changes made with the rude edit, for both a C# syntax error and a generator-reported error (MAUIX2009); - an element added with a rude edit is added once the edit is fixed; - reverting after a rude edit emits the same output as the applied state; - repeated evaluation of a rude edit is deterministic; - an error the user downgraded doesn't roll back (no duplicate element). The first 5 cases fail without the fix. The downgrade case fails if the severity lookup is removed. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter XamlIncrementalHotReloadRudeEditTests`: 6 passed; 5 failed before the fix. - SourceGen.UnitTests, full suite. It was run from a copy of the output in a path without `~`, because the `XTypeMultiFileHotReloadTests` fail when the path contains `~`. Result: **634 passed, 0 failed, 40 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`, built with Apple/Android TFMs excluded because of a local workload mismatch. Result: **2179 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) depend on the dev machine's locale (comma decimal separator) and pass with `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1`. - `dotnet format whitespace --verify-no-changes` on the changed files: clean. ### Issues Fixed Fixes #36156 <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
<!-- 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). This PR targets `candidate/11.0.1xx-sr2`, not `net11`. It's a follow-up to #40235, which was merged into `candidate/11.0.1xx-sr2` and isn't in `net11` (or `main`) yet. The change builds on the code #40235 added. 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 Follow-up to #40235 (fix for #36156). #40235 rolls back the XAML Incremental Hot Reload state (`XamlHotReloadState.Restore`) when a XAML edit can't build. It checks three things: the generator reported an error, the generated IC/UC has C# **syntax** errors, or generation threw. It deliberately skipped **semantic** errors. Members added by other generators (CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`) aren't visible to the XAML generator, so a naive type check would roll back valid edits. As a result, an edit that only fails type checking, such as `{Count.Nope()}` (CS1061), still advanced the baseline. The next valid edit was then diffed against a generation the app never received, and the changes made together with the rude edit were lost. **Fix:** `HasSemanticErrors` type-checks the generated `InitializeComponent` and `UpdateComponent` trees against the generator's compilation (user code plus generated code-behind). It runs only when a XAML edit was diffed, i.e. when a rollback snapshot exists. An error counts only if: - it is located in the generated IC/UC code (errors in user code are ignored), and - `MayBeFixedByAnotherGenerator` returns false for it. That helper ignores errors that a declaration added by another generator could resolve: - unresolved names, types and namespaces (CS0103, CS0234, CS0246, CS0426); - failed member lookup (CS1061, CS0117, …) or overload resolution on a receiver whose type is a **`partial` type declared in source**, the only kind of type other generators can add members to. This also covers `?.` member bindings, implicit-`this` invocations, object creations, and errors reported on an argument. **Options considered:** - *Defer the baseline commit until a later signal confirms the compile.* Rejected: inside the generator there is no such signal. The next run's input compilation never contains the previous output, and nothing tells the generator whether the emit or EnC apply succeeded. - *Count all semantic errors.* Rejected: false rollbacks for MVVM Toolkit members. A false positive is worse than a miss, because the next patch re-adds children that are already live. - *Restrict to diagnostics attributable to XAML-generated code and filter out what another generator could fix.* Chosen. **Known remaining gap:** a lookup on a non-`partial` or metadata type (e.g. `int`) that only an extension method from *another generator* could satisfy still counts as an error. That's rare in XAML expressions. C# 14 extension members generated elsewhere fall in the same case. `XamlHotReloadState` is unchanged. The change is limited to `XamlGenerator.cs`, to keep conflicts with the #40233 follow-up low. **Tests** (`XamlIncrementalHotReloadRudeEditTests`): - `EditAfterRudeEdit_IsDiffedAgainstLastAppliedGeneration(Semantic)`: new case for a type-check-only rude edit, `{Count.Nope()}`. The theory parameter changed from `bool` to a `RudeEdit` enum. - `ElementAddedWithSemanticRudeEdit_IsAddedOnceTheEditIsFixed`: an element added together with a semantic rude edit is added once the edit is fixed. - `MembersGeneratedByAnotherGenerator_DoNotRollBack`: guard. The view model uses `[ObservableProperty]` and `[RelayCommand]`, and the XAML references `Count` (C# expression) and `{Binding SaveCommand}`. The previous edit must not be rolled back, so the added `Button` isn't added again. Without the fix, the 2 semantic cases fail. With `MayBeFixedByAnotherGenerator` disabled, the guard fails. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter FullyQualifiedName~XamlIncrementalHotReloadRudeEditTests`: **9 passed**. Before the fix: 2 failed (the semantic cases), 7 passed. With the filter disabled: 1 failed (the MVVM guard). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` (full suite): **772 passed, 0 failed, 53 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj` with `-p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false`. The mobile TFMs were excluded because of a local workload mismatch. Result: **2250 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) are known and depend on the machine's locale. - `dotnet format whitespace --folder --include <changed files> --verify-no-changes`: clean. ### Issues Fixed Follow-up to #40235. Relates to #36156. <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
…ns (#40378) <!-- 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! ### 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). > [!IMPORTANT] > **Base: `candidate/11.0.1xx-sr2` (decided).** This PR builds on #40233, #40235, #40329 and #40330, which exist only on `candidate/11.0.1xx-sr2` (not on `net11`, `main` or `inflight/11.0.1xx-sr3`). Against `net11` the diff would include about 527 unrelated files. As with #40329 and #40330, it targets `candidate/11.0.1xx-sr2` directly so it ships together with its prerequisites. ### Description of Change #40330 left one limitation. A throwaway generator run with different XAML, such as a design-time or speculative run whose output never reaches the app, advanced the cached previous XAML. The next real `UpdateComponent()` was then diffed from that intermediate generation instead of the generation the running app actually has. The result was missed edits: for example, an edit already present in the throwaway XAML was never applied. The generator cannot tell which of its runs reached the app, so this PR has `UpdateComponent()` decide at runtime: - **Generation key.** Each successful generation gets a key: a SHA-256 of the normalized XAML plus the node IDs (`NodeIdHelper.ComputeGenerationKey`). `XamlHotReloadState` keeps the current generation and the previously generated ones as baselines, up to `MaxBaselines = 4`. - **InitializeComponent** records `XamlComponentRegistry.Register(this, "__xihr_generation:<type>", key)`. - **UpdateComponent** reads the instance's recorded key: - A retained generation whose diff produces exactly the current node IDs gets its own branch: the patch diffed from that generation. - Anything else gets the default patch, diffed from the last generated XAML. This matches the previous behavior. - Every patched instance then records the new key, so running the patch again, or for a C#-only edit, changes nothing. - When there is nothing to patch, the output is unchanged: an empty UC, with no marker. Rude-edit rollback behavior is preserved, and the older applied generation now also gets its own branch. **Known edge, not a regression:** a retained generation whose diff would assign different IDs from the current ones (e.g. some reverts) is not given a branch. Instances at that generation fall back to the default patch, which is the old behavior. ### Issues Fixed Fixes #36937 (remaining limitation from #40330) ### Tests - `XamlIncrementalHotReloadE2ETests.ThrowawayRunWithDifferentXaml_PatchStartsFromTheAppliedGeneration`: real metadata update. Applied `Text="Hello"`, then a throwaway run with `Text="World" FontSize="30"`, then the real edit to `Text="World"`. The live label ends at `World` with its default `FontSize`, re-running UC is a no-op, and new instances are already current. A new harness hook, `GenerateWithThrowawayRuns`, runs and discards a forked driver run. - `XamlIncrementalHotReloadPipelineTests.ThrowawayRunWithDifferentXaml_PatchesFromEveryRetainedGeneration`: checks the branch structure and determinism (same snapshot and C#-only edits give an identical UC). - `XamlIncrementalHotReloadPipelineTests.RetainedGenerations_AreBounded` - Existing rude-edit assertions now target the default patch (`UpdateComponentText.DefaultPatch`), because the UC legitimately contains a branch for the older applied generation. ### Validation - `DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: **passed**, 899/899. - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~HotReload"`: **passed**, 12/12. - `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2274 passed, 12 failed. All 12 failures are `CultureNotFoundException` from culture-specific tests under invariant-globalization mode; none involve hot reload. - `dotnet format whitespace Microsoft.Maui.sln --verify-no-changes --include <changed files>`: **passed**. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…40413) (#40417) <!-- 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). **Base is `candidate/11.0.1xx-sr2`, not `net11`.** The PR is test-only and covers behavior that exists only on the candidate branch, from the #36937 fix chain #40233, #40235, #40329, #40330, and #40378. Against `net11` the test fails, because that fix has not flowed there yet. This follows the precedent of #40329, #40330, and #40378, which targeted this branch for the same reason. Maintainers: retarget if you prefer a different lane. 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 #40413 reports that in VS on Windows (.NET 11, SourceGen inflator, XAML Incremental Hot Reload on by default in Debug), editing a Label's `Text` in the default template's `MainPage.xaml` is not applied. **Root cause.** This is #36937. Roslyn/VS evaluate the same edited generator-driver snapshot more than once, for example forked or speculative runs, or a throwaway compilation before the applied one. On `net11`, the first evaluation advances the cached previous XAML. The evaluation that is actually applied then sees no diff and emits an empty `UpdateComponent`, and the runtime silently skips it. The bug became visible in .NET 11 because XIHR is now the default; 10.0.120 used legacy XAML Hot Reload. I reproduced this with the issue's own template `MainPage.xaml` through the source generator: | Sequence | `net11` (a25e629) | `candidate/11.0.1xx-sr2` (cec6650) | | --- | --- | --- | | Edit evaluated once | patch | patch | | Same edited snapshot evaluated twice: 2nd run | **empty UC** | patch | | Throwaway compilation first, then real run: real run | **empty UC** | patch | On the candidate branch the existing fixes already handle this. This PR adds `DefaultTemplateMainPageTextEdit_SurvivesRepeatedAndThrowawayEvaluations`, a theory with repeated and throwaway-first cases. It uses the template page shape (`StaticResource` styles from a sibling `Styles.xaml`, `x:Name`, a `Clicked` handler in code-behind) to lock in the reported scenario. There are no product changes. **Android .NET 10 (validation comment).** This is a separate scenario. XIHR was not the default in .NET 10, so that report involves the legacy XAML Hot Reload path and is not caused by this regression. It is not addressed here. **Validation** - `DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter "FullyQualifiedName~XamlIncrementalHotReloadPipelineTests|FullyQualifiedName~CodeBehindFieldStabilityTests"`: **passed**, 93/93, on this branch. - `net11`: the same two sequences, run through an equivalent temporary probe with the template XAML, produce an empty UC, as shown in the table. I did not port the committed test itself to `net11`: its helpers exist only on candidate, and reverting the fix commits in place conflicts. - Not verified in Visual Studio on Windows or on device; I worked on a macOS host. ### Issues Fixed Fixes #40413 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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 XAML Incremental Hot Reload (XIHR) keeps per-file state in `XamlHotReloadState` (last XAML, parsed tree, node IDs) and emits `UpdateComponent()` as a diff from the previous generation to the current one. A **rude edit** is a XAML edit whose generated code doesn't compile, for example a malformed XAML C# expression, or an error reported by the generator such as an unresolved member. The build fails, so that edit never reaches the running app. The state had already moved to the broken generation, though. The next, fixed edit was then diffed against the broken generation, not against what the app is running. Changes made together with the rude edit were never applied: property sets, and elements added in the same edit. They stayed lost until a full restart. **Fix:** - Before diffing a XAML edit, the generator captures a copy of the file's state entry (`XamlHotReloadState.Capture`). - After generating `InitializeComponent` and `UpdateComponent`, it restores that entry (`XamlHotReloadState.Restore`) when the generation can't build: - the generator reported an error while generating `InitializeComponent`. A new optional `diagnosticObserver` on `GenerateInitializeComponent` reports these. User severity overrides are honored (`NoWarn`, `WarningsNotAsErrors`, `.editorconfig`/`.globalconfig`), so a downgraded MAUIX error doesn't count; - or the generated IC/UC code has C# **syntax** errors; - or generation throws. - The next edit is then diffed against the last generation that could have been applied. Its patch also carries the changes made together with the rude edit. Re-evaluating the rude edit is deterministic, and reverting to the applied XAML is "no change". **Deliberately not checked: semantic C# errors** in the generated code, such as `{Count.Nope()}` (CS1061). Generated code can legitimately reference members that other generators add later, such as CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`, which `ITypeSymbolExtensions` already infers. A false positive is worse than a miss: it pins the state to a generation the app has already moved past, and the next patch would re-add children, for example. Those edits keep today's behavior. A C#-only compile failure that happens at the same time as a XAML edit is also out of scope. **Interaction with dotnet#40233 (fix for dotnet#36937):** The two are independent, so this PR is not stacked on dotnet#40233. dotnet#40233 adds `PatchBaseline`/`PatchSources` to `CacheEntry` and replays the pending patch when the same inputs are evaluated again. This PR snapshots and restores the whole `CacheEntry` with `MemberwiseClone`, so after a rebase, rolling back a rude edit also restores those fields. The restored state is exactly what the applied generation left, so the output for identical inputs stays identical. Expected conflicts are textual only, in `XamlGenerator.cs` (adjacent lines in the IC output callback) and `XamlHotReloadState.cs`. The new tests are in their own file to avoid conflicts in `XamlIncrementalHotReloadPipelineTests.cs`. **Tests:** new `XamlIncrementalHotReloadRudeEditTests` (6 cases): - an edit after a rude edit carries the changes made with the rude edit, for both a C# syntax error and a generator-reported error (MAUIX2009); - an element added with a rude edit is added once the edit is fixed; - reverting after a rude edit emits the same output as the applied state; - repeated evaluation of a rude edit is deterministic; - an error the user downgraded doesn't roll back (no duplicate element). The first 5 cases fail without the fix. The downgrade case fails if the severity lookup is removed. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter XamlIncrementalHotReloadRudeEditTests`: 6 passed; 5 failed before the fix. - SourceGen.UnitTests, full suite. It was run from a copy of the output in a path without `~`, because the `XTypeMultiFileHotReloadTests` fail when the path contains `~`. Result: **634 passed, 0 failed, 40 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`, built with Apple/Android TFMs excluded because of a local workload mismatch. Result: **2179 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) depend on the dev machine's locale (comma decimal separator) and pass with `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1`. - `dotnet format whitespace --verify-no-changes` on the changed files: clean. ### Issues Fixed Fixes dotnet#36156 <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
…#40329) <!-- 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). This PR targets `candidate/11.0.1xx-sr2`, not `net11`. It's a follow-up to dotnet#40235, which was merged into `candidate/11.0.1xx-sr2` and isn't in `net11` (or `main`) yet. The change builds on the code dotnet#40235 added. 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 Follow-up to dotnet#40235 (fix for dotnet#36156). dotnet#40235 rolls back the XAML Incremental Hot Reload state (`XamlHotReloadState.Restore`) when a XAML edit can't build. It checks three things: the generator reported an error, the generated IC/UC has C# **syntax** errors, or generation threw. It deliberately skipped **semantic** errors. Members added by other generators (CommunityToolkit.Mvvm `[ObservableProperty]` / `[RelayCommand]`) aren't visible to the XAML generator, so a naive type check would roll back valid edits. As a result, an edit that only fails type checking, such as `{Count.Nope()}` (CS1061), still advanced the baseline. The next valid edit was then diffed against a generation the app never received, and the changes made together with the rude edit were lost. **Fix:** `HasSemanticErrors` type-checks the generated `InitializeComponent` and `UpdateComponent` trees against the generator's compilation (user code plus generated code-behind). It runs only when a XAML edit was diffed, i.e. when a rollback snapshot exists. An error counts only if: - it is located in the generated IC/UC code (errors in user code are ignored), and - `MayBeFixedByAnotherGenerator` returns false for it. That helper ignores errors that a declaration added by another generator could resolve: - unresolved names, types and namespaces (CS0103, CS0234, CS0246, CS0426); - failed member lookup (CS1061, CS0117, …) or overload resolution on a receiver whose type is a **`partial` type declared in source**, the only kind of type other generators can add members to. This also covers `?.` member bindings, implicit-`this` invocations, object creations, and errors reported on an argument. **Options considered:** - *Defer the baseline commit until a later signal confirms the compile.* Rejected: inside the generator there is no such signal. The next run's input compilation never contains the previous output, and nothing tells the generator whether the emit or EnC apply succeeded. - *Count all semantic errors.* Rejected: false rollbacks for MVVM Toolkit members. A false positive is worse than a miss, because the next patch re-adds children that are already live. - *Restrict to diagnostics attributable to XAML-generated code and filter out what another generator could fix.* Chosen. **Known remaining gap:** a lookup on a non-`partial` or metadata type (e.g. `int`) that only an extension method from *another generator* could satisfy still counts as an error. That's rare in XAML expressions. C# 14 extension members generated elsewhere fall in the same case. `XamlHotReloadState` is unchanged. The change is limited to `XamlGenerator.cs`, to keep conflicts with the dotnet#40233 follow-up low. **Tests** (`XamlIncrementalHotReloadRudeEditTests`): - `EditAfterRudeEdit_IsDiffedAgainstLastAppliedGeneration(Semantic)`: new case for a type-check-only rude edit, `{Count.Nope()}`. The theory parameter changed from `bool` to a `RudeEdit` enum. - `ElementAddedWithSemanticRudeEdit_IsAddedOnceTheEditIsFixed`: an element added together with a semantic rude edit is added once the edit is fixed. - `MembersGeneratedByAnotherGenerator_DoNotRollBack`: guard. The view model uses `[ObservableProperty]` and `[RelayCommand]`, and the XAML references `Count` (C# expression) and `{Binding SaveCommand}`. The previous edit must not be rolled back, so the added `Button` isn't added again. Without the fix, the 2 semantic cases fail. With `MayBeFixedByAnotherGenerator` disabled, the guard fails. **Validation:** - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter FullyQualifiedName~XamlIncrementalHotReloadRudeEditTests`: **9 passed**. Before the fix: 2 failed (the semantic cases), 7 passed. With the filter disabled: 1 failed (the MVVM guard). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj` (full suite): **772 passed, 0 failed, 53 skipped**. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj` with `-p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeMacOSTargetFrameworks=false`. The mobile TFMs were excluded because of a local workload mismatch. Result: **2250 passed, 2 failed, 8 skipped**. The 2 failures (`TwoWayDecimalBinding_*`) are known and depend on the machine's locale. - `dotnet format whitespace --folder --include <changed files> --verify-no-changes`: clean. ### Issues Fixed Follow-up to dotnet#40235. Relates to dotnet#36156. <!-- 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: Jakub Florkowski <kubaflo123@gmail.com>
…ns (dotnet#40378) <!-- 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! ### 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). > [!IMPORTANT] > **Base: `candidate/11.0.1xx-sr2` (decided).** This PR builds on dotnet#40233, dotnet#40235, dotnet#40329 and dotnet#40330, which exist only on `candidate/11.0.1xx-sr2` (not on `net11`, `main` or `inflight/11.0.1xx-sr3`). Against `net11` the diff would include about 527 unrelated files. As with dotnet#40329 and dotnet#40330, it targets `candidate/11.0.1xx-sr2` directly so it ships together with its prerequisites. ### Description of Change dotnet#40330 left one limitation. A throwaway generator run with different XAML, such as a design-time or speculative run whose output never reaches the app, advanced the cached previous XAML. The next real `UpdateComponent()` was then diffed from that intermediate generation instead of the generation the running app actually has. The result was missed edits: for example, an edit already present in the throwaway XAML was never applied. The generator cannot tell which of its runs reached the app, so this PR has `UpdateComponent()` decide at runtime: - **Generation key.** Each successful generation gets a key: a SHA-256 of the normalized XAML plus the node IDs (`NodeIdHelper.ComputeGenerationKey`). `XamlHotReloadState` keeps the current generation and the previously generated ones as baselines, up to `MaxBaselines = 4`. - **InitializeComponent** records `XamlComponentRegistry.Register(this, "__xihr_generation:<type>", key)`. - **UpdateComponent** reads the instance's recorded key: - A retained generation whose diff produces exactly the current node IDs gets its own branch: the patch diffed from that generation. - Anything else gets the default patch, diffed from the last generated XAML. This matches the previous behavior. - Every patched instance then records the new key, so running the patch again, or for a C#-only edit, changes nothing. - When there is nothing to patch, the output is unchanged: an empty UC, with no marker. Rude-edit rollback behavior is preserved, and the older applied generation now also gets its own branch. **Known edge, not a regression:** a retained generation whose diff would assign different IDs from the current ones (e.g. some reverts) is not given a branch. Instances at that generation fall back to the default patch, which is the old behavior. ### Issues Fixed Fixes dotnet#36937 (remaining limitation from dotnet#40330) ### Tests - `XamlIncrementalHotReloadE2ETests.ThrowawayRunWithDifferentXaml_PatchStartsFromTheAppliedGeneration`: real metadata update. Applied `Text="Hello"`, then a throwaway run with `Text="World" FontSize="30"`, then the real edit to `Text="World"`. The live label ends at `World` with its default `FontSize`, re-running UC is a no-op, and new instances are already current. A new harness hook, `GenerateWithThrowawayRuns`, runs and discards a forked driver run. - `XamlIncrementalHotReloadPipelineTests.ThrowawayRunWithDifferentXaml_PatchesFromEveryRetainedGeneration`: checks the branch structure and determinism (same snapshot and C#-only edits give an identical UC). - `XamlIncrementalHotReloadPipelineTests.RetainedGenerations_AreBounded` - Existing rude-edit assertions now target the default patch (`UpdateComponentText.DefaultPatch`), because the UC legitimately contains a branch for the older applied generation. ### Validation - `DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: **passed**, 899/899. - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~HotReload"`: **passed**, 12/12. - `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2274 passed, 12 failed. All 12 failures are `CultureNotFoundException` from culture-specific tests under invariant-globalization mode; none involve hot reload. - `dotnet format whitespace Microsoft.Maui.sln --verify-no-changes --include <changed files>`: **passed**. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…otnet#40413) (dotnet#40417) <!-- 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). **Base is `candidate/11.0.1xx-sr2`, not `net11`.** The PR is test-only and covers behavior that exists only on the candidate branch, from the dotnet#36937 fix chain dotnet#40233, dotnet#40235, dotnet#40329, dotnet#40330, and dotnet#40378. Against `net11` the test fails, because that fix has not flowed there yet. This follows the precedent of dotnet#40329, dotnet#40330, and dotnet#40378, which targeted this branch for the same reason. Maintainers: retarget if you prefer a different lane. 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 dotnet#40413 reports that in VS on Windows (.NET 11, SourceGen inflator, XAML Incremental Hot Reload on by default in Debug), editing a Label's `Text` in the default template's `MainPage.xaml` is not applied. **Root cause.** This is dotnet#36937. Roslyn/VS evaluate the same edited generator-driver snapshot more than once, for example forked or speculative runs, or a throwaway compilation before the applied one. On `net11`, the first evaluation advances the cached previous XAML. The evaluation that is actually applied then sees no diff and emits an empty `UpdateComponent`, and the runtime silently skips it. The bug became visible in .NET 11 because XIHR is now the default; 10.0.120 used legacy XAML Hot Reload. I reproduced this with the issue's own template `MainPage.xaml` through the source generator: | Sequence | `net11` (a25e629) | `candidate/11.0.1xx-sr2` (cec6650) | | --- | --- | --- | | Edit evaluated once | patch | patch | | Same edited snapshot evaluated twice: 2nd run | **empty UC** | patch | | Throwaway compilation first, then real run: real run | **empty UC** | patch | On the candidate branch the existing fixes already handle this. This PR adds `DefaultTemplateMainPageTextEdit_SurvivesRepeatedAndThrowawayEvaluations`, a theory with repeated and throwaway-first cases. It uses the template page shape (`StaticResource` styles from a sibling `Styles.xaml`, `x:Name`, a `Clicked` handler in code-behind) to lock in the reported scenario. There are no product changes. **Android .NET 10 (validation comment).** This is a separate scenario. XIHR was not the default in .NET 10, so that report involves the legacy XAML Hot Reload path and is not caused by this regression. It is not addressed here. **Validation** - `DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter "FullyQualifiedName~XamlIncrementalHotReloadPipelineTests|FullyQualifiedName~CodeBehindFieldStabilityTests"`: **passed**, 93/93, on this branch. - `net11`: the same two sequences, run through an equivalent temporary probe with the template XAML, produce an empty UC, as shown in the table. I did not port the committed test itself to `net11`: its helpers exist only on candidate, and reverting the fix commits in place conflicts. - Not verified in Visual Studio on Windows or on device; I worked on a macOS host. ### Issues Fixed Fixes dotnet#40413 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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
XAML Incremental Hot Reload (XIHR) keeps per-file state in
XamlHotReloadState(last XAML, parsed tree, node IDs) and emitsUpdateComponent()as a diff from the previous generation to the current one. A rude edit is a XAML edit whose generated code doesn't compile, for example a malformed XAML C# expression, or an error reported by the generator such as an unresolved member. The build fails, so that edit never reaches the running app. The state had already moved to the broken generation, though. The next, fixed edit was then diffed against the broken generation, not against what the app is running. Changes made together with the rude edit were never applied: property sets, and elements added in the same edit. They stayed lost until a full restart.Fix:
XamlHotReloadState.Capture).InitializeComponentandUpdateComponent, it restores that entry (XamlHotReloadState.Restore) when the generation can't build:InitializeComponent. A new optionaldiagnosticObserveronGenerateInitializeComponentreports these. User severity overrides are honored (NoWarn,WarningsNotAsErrors,.editorconfig/.globalconfig), so a downgraded MAUIX error doesn't count;Deliberately not checked: semantic C# errors in the generated code, such as
{Count.Nope()}(CS1061). Generated code can legitimately reference members that other generators add later, such as CommunityToolkit.Mvvm[ObservableProperty]/[RelayCommand], whichITypeSymbolExtensionsalready infers. A false positive is worse than a miss: it pins the state to a generation the app has already moved past, and the next patch would re-add children, for example. Those edits keep today's behavior. A C#-only compile failure that happens at the same time as a XAML edit is also out of scope.Interaction with #40233 (fix for #36937): The two are independent, so this PR is not stacked on #40233. #40233 adds
PatchBaseline/PatchSourcestoCacheEntryand replays the pending patch when the same inputs are evaluated again. This PR snapshots and restores the wholeCacheEntrywithMemberwiseClone, so after a rebase, rolling back a rude edit also restores those fields. The restored state is exactly what the applied generation left, so the output for identical inputs stays identical. Expected conflicts are textual only, inXamlGenerator.cs(adjacent lines in the IC output callback) andXamlHotReloadState.cs. The new tests are in their own file to avoid conflicts inXamlIncrementalHotReloadPipelineTests.cs.Tests: new
XamlIncrementalHotReloadRudeEditTests(6 cases):The first 5 cases fail without the fix. The downgrade case fails if the severity lookup is removed.
Validation:
dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter XamlIncrementalHotReloadRudeEditTests: 6 passed; 5 failed before the fix.~, because theXTypeMultiFileHotReloadTestsfail when the path contains~. Result: 634 passed, 0 failed, 40 skipped.dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj, built with Apple/Android TFMs excluded because of a local workload mismatch. Result: 2179 passed, 2 failed, 8 skipped. The 2 failures (TwoWayDecimalBinding_*) depend on the dev machine's locale (comma decimal separator) and pass withDOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1.dotnet format whitespace --verify-no-changeson the changed files: clean.Issues Fixed
Fixes #36156