Skip to content

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

Merged
kazo0 merged 4 commits into
mainfrom
dev/mara/fix-routes-hr
Aug 24, 2026
Merged

kazo0 merged 4 commits into
mainfrom
dev/mara/fix-routes-hr

Conversation

@rajamatt

@rajamatt rajamatt commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

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):

@rajamatt rajamatt self-assigned this Aug 20, 2026
@rajamatt
rajamatt force-pushed the dev/mara/fix-routes-hr branch from 465148d to 7b53165 Compare August 20, 2026 16:44
rajamatt and others added 2 commits August 20, 2026 13:03
…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]>
- 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]>
@rajamatt
rajamatt force-pushed the dev/mara/fix-routes-hr branch from 2147277 to b6c8774 Compare August 20, 2026 17:17
@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 228993 has failed on uno.extensions.

…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]>
@kazo0
kazo0 merged commit d093b5b into main Aug 24, 2026
17 of 18 checks passed
@kazo0
kazo0 deleted the dev/mara/fix-routes-hr branch August 24, 2026 21:05
pull Bot pushed a commit to ehtick/uno.extensions that referenced this pull request Aug 25, 2026
Layer 1/4 of the MSAL authentication work (unoplatform#3139): the device lanes, without
any MSAL code. Build stages publish each head as a pipeline artifact; test
stages boot an emulator / simulator / headless browser, run the engine with a
namespace filter and harvest NUnit results. Ported from Studio Live's setup.

- Four lanes (stage-runtime-tests-{desktop,wasm,android,ios}.yml) fed by
  stage-build-runtimetests-mobile.yml; scripts under build/test-scripts with
  bounded waits, inline emulator logs and a results validator that fails on an
  empty or all-skipped run
- Runtime-test head: MobileRuntimeTestsAutostart drives UnitTestsControl and
  writes the NUnit document on Android/iOS (the engine's own runner throws
  PlatformNotSupportedException in a sandboxed app); WebAssemblyRuntimeShim
  supplies the __WASM__ symbol and InvokeJS the source-shipped engine needs;
  MainActivity uses GetExternalFilesDir for the results path; the iOS head
  carries the keychain entitlement MSAL's cache accessor demands
- src/Directory.Build.targets exempts AndroidApplication heads from the
  library-only Private=false rule: .NET Android rewrites an app head's
  OutputType to Library, which emptied ReferenceCopyLocalPaths and shipped
  APKs without their ProjectReference closure
- src/Directory.Build.props turns the trim/AOT analyzers off for test and
  sample projects; they only turned "this test calls the API it exists to
  test" into IL2026 errors on the WebAssembly heads
- Given_NavigationRouteUpdateHandler (unoplatform#3146, merged under this branch) becomes
  partial: the Android/iOS native-ctor generator emits a partial for it, and
  main never compiles the Navigation UI tests for a device TFM, so these lanes
  are the first build to see CS0260
- RuntimeTestsFilter is Storage.UI.Tests: green on every lane today. The
  MSAL namespace joins it in the next layer; '!_HotReload' waits on 15 rotted
  cases in the wider suite

AGENTS.md records the new Window() rule (mobile rejects secondary windows);
specs/lessons.md the CI lessons.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EqfQh5ovrPEvFGcERLiLhH
@kazo0

kazo0 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

@Mergifyio backport release/stable/7.3

@mergify

mergify Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

backport release/stable/7.3

✅ Backports have been created

Details

kazo0 added a commit that referenced this pull request Aug 26, 2026
….3/pr-3146

fix: re-instantiate the active route's view model on hot reload (backport #3146)
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.

[HR][Navigation] CascadeNewDefaultsFromRoot suppresses the refresh of the active route, so the displayed page is never re-instantiated

3 participants