Skip to content

fix(mvux): keep bindables on the updated model when an HR delta adds a derived feed - #3230

Merged
kazo0 merged 3 commits into
mainfrom
dev/sb/mvux-hr-derived-feed
Oct 14, 2026
Merged

kazo0 merged 3 commits into
mainfrom
dev/sb/mvux-hr-derived-feed

Conversation

@kazo0

@kazo0 kazo0 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): closes #3226

PR Type

  • Bugfix

What is the current behavior?

After a Hot Reload delta that adds a feed derived from an existing state (e.g. IsGoalReached => Count.Select(c => c >= 10)), commands keep running but the UI no longer reflects them: Count stays at 0.

A bindable property follows a hot-patch only if the patcher swaps the shared subscription the bindable enumerates (keyed by the feed the bindable was created from). Two causes broke that:

  1. Live view model (derived feed subscribes too early). The generated __Reactive_UpdateModel initialized members from the updated model before patching. The new derived feed subscribed to the updated Count state, so SetSubscription(updated, shared) threw on the key conflict and the swap after it never ran.
  2. Recreated view model (the scenario in the issue). A page recreated after the delta builds its view model with the EnC-updated constructor, then self-patches. That constructor's model.Count and the patcher's reflection read of Count on the original model type run different getters, each with its own () => 0 lambda. State.Value (like Feed.Async) caches per lambda, so the same model instance yields two states. The patcher swapped the subscription of a state no bindable used.

What is the new behavior?

  • Generator (ViewModelGenTool_3, _2): patch first, then initialize.
  • Runtime (BindableViewModelBase):
    • Property(name, feed) records the feed each bindable is created from (only when state hot reload is enabled), and the patcher swaps that tracked feed rather than a fresh read of the previous model.
    • Hot-swap happens before SetSubscription. A key conflict is logged and the previous feed stays tracked, so the next delta still finds the shared subscription. ObjectDisposedException still propagates.

PR Checklist

  • Tested code with current supported SDKs
  • Docs have been added/updated (spec 015, HotReload.Spec.md §4.13, specs/lessons.md)
  • Unit Tests and/or UI Tests for the changes have been added
  • Wasm UI Tests are not showing unexpected differences
  • Contains NO breaking changes
  • Updated the Release Notes
  • Associated with an issue

Other information

Tests:

  • Unit, Reactive.Tests/IntegrationTests/Given_HotReload.cs:
    • When_AddDerivedFeedInModel_Then_StateBindableFollowsUpdatedModel (cause 1, plus a second delta). Red on main.
    • When_ViewModelCreatedAfterDelta_Then_CommandsUpdateBoundState (cause 2, emulates the getter divergence). Red without feed tracking.
  • Runtime HR, Reactive.UI.Tests/Given_HotReload.cs: When_AddDerivedFeedToModelWithStateAndCommand_Then_CommandUpdatesBoundState covers both the live view model and one created after the delta.

Verification (Windows, desktop head, real HR deltas):

Run Result
New runtime test on main Failed: recreated VM expected "2", actual "0"
New runtime test with only the cause 1 fixes Failed, same assertion
New runtime test with the full fix Passed
All 14 Reactive Given_HotReload runtime tests with the full fix 14 passed
Reactive unit suite 1471 passed, 19 skipped

Flaky tests:

  • Given_StateForEach.When_Mixed_Multiple_UpdateState_Then_CallbackInvokedIgnoringInitialValue failed the Packages job on this PR. It is a pre-existing race: SetAsync completes before ForEach callbacks run, and the test asserted immediately (it fails ~20% of local runs on main too). A separate test-only commit replaces the immediate assertions, and an older fixed 100 ms delay, with a bounded wait for the expected callbacks in the five tests sharing that race.
  • Given_PaginatedListFeed.When_Async_Then_FlagIsLoading fails intermittently under full-suite load, on main too (2 of 5 runs). It passes alone and is not touched here.

The "Build and Deploy Job" (Azure Static Web Apps docs preview) fails because the Static Web App has reached its maximum number of staging environments. Someone with Azure access needs to delete old preview environments; nothing in this PR affects it.

Running the HR lane on Windows needs a specific build: both head target frameworks, with hard links off. The recipe is in specs/lessons.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Bnp4Xi4RAU2pnfN9PNRUph

…a derived feed

- Patch bindable properties before initializing members from the updated model, so the shared
  subscription is re-keyed onto the new feed before a newly added derived feed subscribes to it
- Hot-swap the shared subscription before re-keying it, and log a key conflict instead of
  aborting the property, so the bindable follows the updated model in every case
- Add a unit repro (red on main) covering the added feed and a second delta, a runtime HR test
  mirroring the issue, spec 015, and a lesson on running the HR lane on Windows

Closes #3226

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Bnp4Xi4RAU2pnfN9PNRUph
…els recreated after HR

- Record the feed each bindable property is created from (state hot reload only), and have the
  patcher swap that feed's subscription instead of re-reading the property from the previous model
- After a delta, the EnC-updated view-model ctor and reflection on the original model type can run
  different getters, each with its own cached lambda, so `State.Value`/`Feed.Async` returned another
  state and the bindable of a recreated page never followed the updated model
- On a re-key conflict, keep tracking the previous feed, which still resolves to the shared subscription
- Cover the recreated view model in the runtime HR test (red on main, green locally) and add a unit
  repro of the getter divergence; document how to run the HR lane on Windows

Refs #3226

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Bnp4Xi4RAU2pnfN9PNRUph
@kazo0
kazo0 enabled auto-merge October 14, 2026 15:06
@kazo0

kazo0 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio backport servicing/7.4

@mergify

mergify Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

backport servicing/7.4

✅ Backports have been created

Details

…n_StateForEach

- `SetAsync` completes once the state applied the update, not once ForEach callbacks ran, so
  asserting right after it was flaky (`When_Mixed_Multiple_UpdateState_...` failed CI on this PR,
  and fails ~20% of local runs on main too)
- Replace the immediate assertions and the fixed 100 ms delay with a bounded wait for the
  expected callback count, so a dropped callback still fails the test

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Bnp4Xi4RAU2pnfN9PNRUph

@dr1rrb dr1rrb left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Superseded by #3230 (review), trimmed down to the two comments that still apply.

@dr1rrb dr1rrb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

➡️ Medium — 1 medium, 1 low

Nothing blocking: both causes are fixed, and tracking the feed the bindable was created from is the right invariant. The two remaining comments are on the tests only.

  1. Bound the await tcs.Task in When_AddDerivedFeedInModel_Then_StateBindableFollowsUpdatedModel, and create the first tcs right before the delta.
  2. Use WaitFor instead of TryWaitFor + Assert in the runtime test.

@kazo0
kazo0 disabled auto-merge October 14, 2026 18:47
@kazo0
kazo0 merged commit 61a4771 into main Oct 14, 2026
25 of 26 checks passed
@kazo0
kazo0 deleted the dev/sb/mvux-hr-derived-feed branch October 14, 2026 18:47
@mergify

mergify Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

kazo0 added a commit that referenced this pull request Oct 26, 2026
…-3230

fix(mvux): keep bindables on the updated model when an HR delta adds a derived feed (backport #3230)
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][MVUX] After a Hot Reload edit that adds a feed to the model, commands update a model the UI no longer shows

2 participants