Skip to content

fix(binding): reapply cached source values during UpdateTarget - #21756

Merged
MrJul merged 2 commits into
AvaloniaUI:mainfrom
NathanDrake2406:nathan/fix-21746-update-target-explicit
Jul 20, 2026
Merged

fix(binding): reapply cached source values during UpdateTarget#21756
MrJul merged 2 commits into
AvaloniaUI:mainfrom
NathanDrake2406:nathan/fix-21746-update-target-explicit

Conversation

@NathanDrake2406

Copy link
Copy Markdown
Contributor

What does the pull request do?

Fixes #21746. Restores the documented UpdateTarget contract for explicit two-way bindings when a target edit has not been written to the source.

What is the current behavior?

After a target is changed under UpdateSourceTrigger=Explicit, UpdateTarget rebuilds the binding path but does not restore the unchanged source value. The binding expression already caches that value, so equal-value suppression prevents the value store from receiving a refresh and the target remains edited.

What is the updated/expected behavior with this PR?

UpdateTarget re-applies the source value even when it matches the expression cache. Calling it after an uncommitted explicit two-way target edit now restores the target from the source without modifying the source.

How was the solution implemented (if it's not obvious)?

The binding tracks the synchronous UpdateTarget rebuild and forces value publication only while that rebuild is in progress. Normal binding notification deduplication is unchanged. A counter and finally block keep the state correct for nested calls and exceptions.

Checklist

Breaking changes

None.

Obsoletions / Deprecations

None.

Fixed issues

Fixes #21746

Validation

  • dotnet build src/Avalonia.Base/Avalonia.Base.csproj -p:AvsSkipBuildingLegacyTargetFrameworks=True
  • dotnet run --project tests/Avalonia.Base.UnitTests/Avalonia.Base.UnitTests.csproj -- --filter-class Avalonia.Base.UnitTests.Data.Core.BindingExpressionTests+Reflection Avalonia.Base.UnitTests.Data.Core.BindingExpressionTests+Compiled

The focused regression runs in both the reflection and compiled paths.

grokys and others added 2 commits July 9, 2026 23:00
UpdateTarget did not restore an uncommitted explicit two-way target value when the source still matched the binding expression's cached value. Equal-value suppression then prevented ValueStore from receiving the refresh.\n\nTrack the synchronous UpdateTarget rebuild and force publication only for that path, so the source value is reapplied without changing normal binding notification deduplication. The preceding regression test covers the observable behavior in both reflection and compiled binding paths.
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0067426-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added bug area-bindings backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Jul 11, 2026

@MrJul MrJul 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.

LGTM!

@MrJul
MrJul added this pull request to the merge queue Jul 20, 2026
Merged via the queue into AvaloniaUI:main with commit c3a5c49 Jul 20, 2026
11 checks passed
MrJul pushed a commit that referenced this pull request Jul 29, 2026
* Added failing test for #21746.

* fix(binding): reapply cached source values during UpdateTarget

UpdateTarget did not restore an uncommitted explicit two-way target value when the source still matched the binding expression's cached value. Equal-value suppression then prevented ValueStore from receiving the refresh.\n\nTrack the synchronous UpdateTarget rebuild and force publication only for that path, so the source value is reapplied without changing normal binding notification deduplication. The preceding regression test covers the observable behavior in both reflection and compiled binding paths.

---------

Co-authored-by: grokys <grokys@users.noreply.github.com>
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UpdateTarget does not revert value when UpdateSourceTrigger is Explicit

4 participants