Skip to content

fix: re-instantiate the active route's view model on hot reload (backport #3146) - #3168

Merged
kazo0 merged 4 commits into
release/stable/7.3from
mergify/bp/release/stable/7.3/pr-3146
Aug 26, 2026
Merged

kazo0 merged 4 commits into
release/stable/7.3from
mergify/bp/release/stable/7.3/pr-3146

Conversation

@mergify

@mergify mergify Bot commented Aug 26, 2026

Copy link
Copy Markdown

GitHub Issue (If applicable): closes #3142

PR Type

What kind of change does this PR introduce?

  • Bugfix

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.UpdateApplication rebuilds the route table and correctly
    classifies the delta as navigation-relevant, but CascadeNewDefaultsFromRoot suppresses the
    walk because the region is already on that route (the suppression itself is correct — it
    preserves the user's selection).
  • FrameNavigator.RehookCurrentViewAfterHotReload only reacts when the frame's content element
    was replaced; a metadata-only edit to a plain C# view-model class replaces no element.
  • RetryPendingFailedRequestsFromRoot only re-issues failed requests.

Re-issuing the same route is also a no-op end to end: FrameNavigator.NavigateForwardAsync
computes 0 forward segments for the route it is already on, and its HR bypass only fires when
SourcePageType differs from the mapping's RenderView — 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 updatedTypes into the cascade's
conflict check — CascadeNewDefaultsFromRoot is unchanged):

  • NavigationRouteUpdateHandler.ScheduleCascade now receives updatedTypes.
    CollectUpdatedViewModels maps each updated type to the view-model type the just-rebuilt route
    table associates with it, resolved through RouteResolver.FindByViewModel so the MVUX case
    works (MappedRouteResolver translates a model type — what the delta contains — to its
    generated bindable view model — what RouteInfo.ViewModel holds).
  • RefreshUpdatedActiveRoutesFromRoot walks the live region tree; every region whose navigator's
    active Route.Base resolves to a mapping whose ViewModel is in that set gets the new
    ControlNavigator.RefreshActiveRouteViewModelAsync(), which re-runs the standard
    InitializeCurrentView(refresh: true) pipeline (CreateViewModel +
    InjectServicesAndSetDataContextAsync) for the route the navigator is already on.
  • View types deliberately do not trigger the refresh: updated views are owned by Uno's
    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_CopiedViewModelIsPreserved pins.
  • updatedTypes == null (unknown delta) refreshes nothing — conservative, mirrors the existing
    x:Uid-revert guard on the cascade.

Known limitation (documented in specs/009-hr-active-route-vm-refresh/spec.md): a view model
replaced via CreateNewOnMetadataUpdate (rude edit / some partial-class deltas) resolves to the
old 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 as
    Given_FrameContentRehook): drives the internal HR entry point with a synthetic delta against
    a 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 (runtime
    test, 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
    IsDefault route. Runs in the hot-reload runtime-test CI stage.
  • Given_NavigationRouteUpdateHandler: 5 unit tests for CollectUpdatedViewModels
    (null / unregistered / registered VM / registered view-only / MVUX mapped-model).
  • Existing guard suites verified green: Given_FrameContentRehook (state preservation
    unchanged), 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 it
required breaking hot reload badly enough to force a full rebuild.

Design doc: specs/009-hr-active-route-vm-refresh/spec.md (+ scenario entry in
src/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).

rajamatt and others added 4 commits August 26, 2026 18:25
…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)
@mergify

mergify Bot commented Aug 26, 2026

Copy link
Copy Markdown
Author

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@kazo0
kazo0 merged commit c12a3c9 into release/stable/7.3 Aug 26, 2026
13 checks passed
@kazo0
kazo0 deleted the mergify/bp/release/stable/7.3/pr-3146 branch August 26, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants