Repository navigation
fix: re-instantiate the active route's view model on hot reload (backport #3146) - #3168
Merged
Merged
Conversation
(cherry picked from commit 7b53165)
…Q pipeline - replaces the foreach + inline null-check in CollectUpdatedViewModels with Select/OfType/ToHashSet, per code-quality review - behavior unchanged; IL2072 suppression kept around the resolver lookup Co-Authored-By: Claude Fable 5 <[email protected]> (cherry picked from commit df5f6e7)
- the LINQ refactor moved the FindByViewModel call into a lambda, shifting the trim-analyzer diagnostic from IL2072 to IL2067; the carried-over suppression no longer matched and browserwasm failed with warnings-as-errors - verified locally on net9.0-browserwasm: IL2067 reproduces on the previous commit and is clean with this one Co-Authored-By: Claude Fable 5 <[email protected]> (cherry picked from commit b6c8774)
…eload - CollectUpdatedViewModels was the first caller to pass view types to FindByViewModel; on a miss, RouteResolverDefault's convention fallback derives the view's own route path from the type name and REPLACES the registered mapping with one whose ViewModel is the view type — corrupting the route table on every XAML delta (the Given_TabBar_HotReload CI regression) and refreshing pages with a page instance as DataContext - filter FrameworkElement-derived types out before the lookup; the pre-existing HasRouteRegisteredType was safe only because its FindByView call short-circuits first - red/fix/green: new unit test on RouteResolverDefault pins the empty result AND the intact route table; the view-only-delta integration test now also asserts the registered mapping survives the walk Co-Authored-By: Claude Fable 5 <[email protected]> (cherry picked from commit a64cdcb)
kazo0
approved these changes
Aug 26, 2026
kazo0
enabled auto-merge
August 26, 2026 18:25
Author
|
Tick the box to add this pull request to the merge queue (same as
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GitHub Issue (If applicable): closes #3142
PR Type
What kind of change does this PR introduce?
What is the current behavior?
A C# hot-reload delta that updates the view model of the currently displayed route never
re-instantiates that view model, so edits that only run at construction time (constructor bodies,
property initializers) stay invisible until a full rebuild — the one page guaranteed not to
refresh is the page the user is looking at.
Every existing HR path declines to handle it:
NavigationRouteUpdateHandler.UpdateApplicationrebuilds the route table and correctlyclassifies the delta as navigation-relevant, but
CascadeNewDefaultsFromRootsuppresses thewalk because the region is already on that route (the suppression itself is correct — it
preserves the user's selection).
FrameNavigator.RehookCurrentViewAfterHotReloadonly reacts when the frame's content elementwas replaced; a metadata-only edit to a plain C# view-model class replaces no element.
RetryPendingFailedRequestsFromRootonly re-issues failed requests.Re-issuing the same route is also a no-op end to end:
FrameNavigator.NavigateForwardAsynccomputes 0 forward segments for the route it is already on, and its HR bypass only fires when
SourcePageTypediffers from the mapping'sRenderView— which it doesn't for an in-place(EnC) update.
What is the new behavior?
When a hot-reload delta updates the view model mapped to a region's active route, that view
model is re-created in place and rebound — no navigation is issued, so the user's selection
cannot move.
Implementation (two orthogonal walks instead of entangling
updatedTypesinto the cascade'sconflict check —
CascadeNewDefaultsFromRootis unchanged):NavigationRouteUpdateHandler.ScheduleCascadenow receivesupdatedTypes.CollectUpdatedViewModelsmaps each updated type to the view-model type the just-rebuilt routetable associates with it, resolved through
RouteResolver.FindByViewModelso the MVUX caseworks (
MappedRouteResolvertranslates a model type — what the delta contains — to itsgenerated bindable view model — what
RouteInfo.ViewModelholds).RefreshUpdatedActiveRoutesFromRootwalks the live region tree; every region whose navigator'sactive
Route.Baseresolves to a mapping whoseViewModelis in that set gets the newControlNavigator.RefreshActiveRouteViewModelAsync(), which re-runs the standardInitializeCurrentView(refresh: true)pipeline (CreateViewModel+InjectServicesAndSetDataContextAsync) for the route the navigator is already on.element-update walk (plus the frame-content re-hook), and rebuilding view models on a view-only
delta would discard un-persisted view-model state on every page edit — the behavior
Given_FrameContentRehook.When_XamlOnlyDelta_Then_CopiedViewModelIsPreservedpins.updatedTypes == null(unknown delta) refreshes nothing — conservative, mirrors the existingx:Uid-revert guard on the cascade.
Known limitation (documented in
specs/009-hr-active-route-vm-refresh/spec.md): a view modelreplaced via
CreateNewOnMetadataUpdate(rude edit / some partial-class deltas) resolves to theold type in the rebuilt route table and is not matched — same pre-existing limitation as the
route table itself (#3072). The in-place EnC case (type identity preserved) is fully covered.
Other information
Tests added (red/fix/green — the repro tests fail on
main):Given_ActiveRouteVmRefresh(UI test, no HR harness — same technique asGiven_FrameContentRehook): drives the internal HR entry point with a synthetic delta againsta live navigation tree. Asserts the VM is rebuilt in place (view instance untouched) for a
VM delta, and preserved for a view-only delta. Verified red before the fix (timeout — nothing
re-instantiates the VM) and green after, on Skia desktop.
Given_HotReload.When_ActiveRouteViewModelUpdated_Then_ActiveRegionVmReinstantiated(runtimetest, real HR delta, secondary app): edits a constructor-seeded property initializer on the
active route's own VM file while sitting on a non-default visibility-region route; asserts
the VM is re-instantiated with the post-HR seed AND the selection is not yanked back to the
IsDefaultroute. Runs in the hot-reload runtime-test CI stage.Given_NavigationRouteUpdateHandler: 5 unit tests forCollectUpdatedViewModels(null / unregistered / registered VM / registered view-only / MVUX mapped-model).
Given_FrameContentRehook(state preservationunchanged),
Given_NavigationRouteUpdateHandler, neighboring navigation suites.Also validated end-to-end in a downstream consumer: with this assembly, editing a chart series
property initializer on the displayed page's model (
ColumnSeries<double>→LineSeries<double>) renders live on the active page in one hot-reload pass — previously itrequired breaking hot reload badly enough to force a full rebuild.
Design doc:
specs/009-hr-active-route-vm-refresh/spec.md(+ scenario entry insrc/Uno.Extensions.Navigation.UI.Tests/HotReload.Spec.md).Internal Issue (If applicable):
This is an automatic backport of pull request #3146 done by [Mergify](https://mergify.com).