Skip to content

fix(maui): reload the view on hot reload - #53

Open
michaelstonis wants to merge 1 commit into
developfrom
fix/maui-hot-reload-never-reloads
Open

michaelstonis wants to merge 1 commit into
developfrom
fix/maui-hot-reload-never-reloads

Conversation

@michaelstonis

Copy link
Copy Markdown
Contributor

Why

MauiViewManager.HandleHotReload returned early whenever its view was still alive:

if (_reloadView is null || _reloadView.TryGetTarget(out var target) || target is not IStellarView<TViewModel> isv)
{
    return;
}

A live view makes TryGetTarget true and returns; a collected one leaves target null and returns. isv.ReloadView() was unreachable. The negation was dropped in d33cee3 (December 2023), when the field moved from WeakReference to WeakReference<T> (previously !(_reloadView?.IsAlive ?? false)), so MAUI hot reload has not re-run SetupUserInterface and the bindings since. The Avalonia, Uno, WinUI and WPF view managers hold the view directly and are not affected.

Found while reviewing v2.1.3...v2.2.0; the line predates that range.

What

Restores the !, and adds a test that raises the hot reload event for a view in a window.

Verification

  • The new test fails without the fix and passes with it. It can only assert that ReloadView reaches its main-thread hand-off, because a test host has no main thread; the reload itself is not exercised.
  • Stellar.Maui.UnitTests: 196/196 locally on net10.0.
  • Not verified in a running app with hot reload attached.

🤖 Generated with Claude Code

The handler returned early whenever its view was still alive: a refactor
to WeakReference<T> in December 2023 dropped the negation in front of
TryGetTarget, so ReloadView has not run on hot reload since.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 5, 2026 21:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The new test leaves a handler attached to a process-wide static event, leaking state into later tests.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes MAUI hot reload so live Stellar views receive reload events.

Changes:

  • Corrects the weak-reference target check.
  • Adds regression coverage for a view attached to a window.
File Description
Stellar.Maui/​MauiViewManager.cs Restores hot-reload dispatch to live views.
Stellar.Maui.UnitTests/​HotReloadSubscriptionTests.cs Tests hot-reload event delivery.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +78 to +79
Assert.NotNull(thrown);
GC.KeepAlive(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants