Skip to content

fix: report a runtime property chain's initial value once when a link emits on subscribe - #162

Merged
glennawatson merged 1 commit into
mainfrom
fix/chain-initial-value-once
Oct 1, 2026
Merged

glennawatson merged 1 commit into
mainfrom
fix/chain-initial-value-once

Conversation

@glennawatson

Copy link
Copy Markdown
Contributor

Summary

A runtime property chain reports its initial value once, even when a link has no change notification.

  • WhenAnyValueUnsafe, WhenChanged and the other reflection-based observations report one initial value. This holds when a link in the chain is a plain property with no change notification.
  • BindUnsafe does not write back to the view model when the binding is created. This holds when the view raises no change notification of its own.

Why

A link that emits as soon as you subscribe produced a second initial value.

  • The fallback provider for a property with no change notification emits once on subscribe. The chain also reads the value itself right after it subscribes. A plain property in the middle of a chain re-attached the rest of the chain twice. A plain property at the end of a chain sent its value twice.
  • isDistinct did not collapse the repeat. With skipInitial, the chain still let the initial value through.
  • A two-way binding saw the second value on the view side and wrote it back to the view model.

Closes #160

Breaking changes

None

How this was verified

  • Tests cover a plain property in the middle of a chain and at the end, with and without skipInitial. They also cover a two-way binding through a view that raises no notification.
  • Ran the Linux examples suite and the Windows examples suite on a Windows guest.

Notes for the reviewer

The whole fix is in ExpressionChainSink.cs.

  • Each link sets a flag while it subscribes. A notification that arrives while the flag is set is ignored, because the chain reads the same value straight after.
  • The flag is only read under the chain's lock. Only a notification raised from inside Subscribe on the same thread can see it. Notifications from other threads still wait on the lock and are delivered as before.
  • The fix covers any provider that emits on subscribe, not only the fallback one.

Checklist

  • I have read the Contribute guide
  • The PR title follows Conventional Commits
  • Tests cover this change, or the summary says why they do not
  • New or changed public API has XML documentation

… emits on subscribe

- Ignore a link notification raised from inside its own subscribe. The chain reads the same value straight after.
- WhenAnyValueUnsafe, WhenChanged and the Unsafe bindings report one initial value through a property with no change notification.
- BindUnsafe does not write the view's value back to the view model when the binding is created.

Fixes #160
@glennawatson
glennawatson enabled auto-merge (squash) October 1, 2026 06:09
@codecov

codecov Bot commented Oct 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.23%. Comparing base (760b967) to head (55f58a5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #162   +/-   ##
=======================================
  Coverage   99.23%   99.23%           
=======================================
  Files         396      396           
  Lines       14467    14469    +2     
  Branches     2065     2065           
=======================================
+ Hits        14357    14359    +2     
  Misses        110      110           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

sonarqubecloud Bot commented Oct 1, 2026

Copy link
Copy Markdown

@glennawatson
glennawatson merged commit 397cd84 into main Oct 1, 2026
23 checks passed
@glennawatson
glennawatson deleted the fix/chain-initial-value-once branch October 1, 2026 06:33
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.

[Bug]: Runtime WhenAnyValue / WhenChanged emits the initial value more than once when a chain link has no change notification

1 participant