Skip to content

test: Add regression test for #2872 - #22991

Merged
MartinZikmund merged 3 commits into
masterfrom
dev/mazi/repro/2872
Jun 24, 2026
Merged

MartinZikmund merged 3 commits into
masterfrom
dev/mazi/repro/2872

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

Summary

Adds regression test for #2872.

The reported issue appears to be potentially fixed — the test(s) pass on current master (Skia target).

Test(s) added

  • src/Uno.UI.RuntimeTests/Tests/BindingTests/Given_XBind_NavigatedTo.cs → When_XBind_Updated_After_DataContext_Set_In_OnNavigatedTo
  • src/Uno.UI.RuntimeTests/Tests/BindingTests/XBind_NavigatedTo_Page.xaml + .xaml.cs (test page)

Notes

The issue was reported on iOS, Android, WebAssembly. Runtime tests run on Skia only — the fix should be verified on native targets as well.

The test verifies that x:Bind reflects property values set during OnNavigatedTo when an await precedes navigation. It navigates to a page that sets DataContext in OnNavigatedTo, triggering DataContextChanged which updates a bound property and calls Bindings.Update().

Relates to #2872

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.

Pull request overview

Adds a new runtime regression test intended to cover #2872 (x:Bind evaluation timing vs. OnNavigatedTo / DataContextChanged).

Changes:

  • Added a new MSTest case that navigates after an await to simulate the reported scenario.
  • Added a dedicated XAML Page + code-behind to reproduce the OnNavigatedTo/DataContextChanged update sequence.
  • Wired the test to run on UI thread and linked it to the GitHub work item.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/Uno.UI.RuntimeTests/Tests/BindingTests/Given_XBind_NavigatedTo.cs Introduces the regression test that performs delayed navigation and asserts expected post-navigation state.
src/Uno.UI.RuntimeTests/Tests/BindingTests/XBind_NavigatedTo_Page.xaml Adds a minimal repro page with x:Bind to BoundText.
src/Uno.UI.RuntimeTests/Tests/BindingTests/XBind_NavigatedTo_Page.xaml.cs Implements OnNavigatedTo + DataContextChanged behavior intended to trigger the binding timing scenario.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@unodevops

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or it will be closed in 10 days.

@github-actions github-actions Bot added the stale This item has been marked as stale and will be closed if there is no activity. label Jun 8, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 10 days with no activity.

@github-actions github-actions Bot closed this Jun 18, 2026
@MartinZikmund MartinZikmund removed the stale This item has been marked as stale and will be closed if there is no activity. label Jun 22, 2026
@MartinZikmund MartinZikmund reopened this Jun 22, 2026
@github-actions

github-actions Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 2m 8s —— View job


Review complete

  • Gather context
  • Read changed files
  • Review test class (Given_XBind_NavigatedTo.cs)
  • Review XAML page (XBind_NavigatedTo_Page.xaml)
  • Review code-behind (XBind_NavigatedTo_Page.xaml.cs)
  • Post inline comments
  • Update summary comment

Summary

The approach is sound — a Frame-based navigation test that exercises OnNavigatedTo/DataContextChanged timing is the right shape for this regression. Two issues undermine its correctness as a regression guard, plus three minor quality issues:

Blocking (2):

  • protected internal on OnNavigatedTo (XBind_NavigatedTo_Page.xaml.cs:20) — compile error on Windows builds. WinUI declares this protected; override must match. Change to protected override.
  • Bindings.Update() masks the bug (XBind_NavigatedTo_Page.xaml.cs:16) — calling Bindings.Update() inside DataContextChanged is the documented workaround for the original issue. With it in place the test will pass even if the timing regression re-introduces, because the manual refresh covers it. Remove it; the test should pass only if x:Bind updates on its own.

Minor (3):

  • Assert on TextBlock.Text, not just BoundText (Given_XBind_NavigatedTo.cs:44) — the original bug manifests as a stale UI value, not a stale property. The test should verify TheTextBlock.Text (via FindName + WaitFor) to actually catch the regression.
  • Replace Task.Delay(200) with Task.Yield() (Given_XBind_NavigatedTo.cs:30) — a yield is sufficient to create the async continuation that triggers the timing issue; the 200 ms fixed cost is unnecessary.
  • Remove unused using static (Given_XBind_NavigatedTo.cs:5) — Private.Infrastructure.TestServices is not referenced in this file.

Validation evidence:

  • Code review assessment: issues identified above.
  • Compile validation: not run locally.
  • Runtime validation: not run locally. The PR author notes the test passes on Skia; once the Bindings.Update() workaround is removed, the test should be re-verified to ensure it still passes (confirming the issue is actually fixed) and would fail on a regressed build.

@unodevops

Copy link
Copy Markdown
Contributor

MartinZikmund and others added 2 commits June 24, 2026 09:38
Address PR review feedback on #22991:

- Fix native WinUI build: gate OnNavigatedTo's `internal` modifier
  behind `#if HAS_UNO`. Uno's Page.OnNavigatedTo is
  `protected internal virtual` while WinUI's is `protected`, so the
  override must drop `internal` on native WinUI. Matches the
  SourceTypePage pattern in Given_Frame.
- Remove the Bindings.Update() workaround from DataContextChanged so
  the test no longer masks the original timing regression.
- Assert the rendered TheTextBlock.Text (via FindName + WaitFor), not
  just the backing BoundText property, to catch the stale-UI case.
- Use Task.Yield() instead of Task.Delay(200) for the async break.

Kept `using static Private.Infrastructure.TestServices;` (reviewers
suggested removing it): WindowHelper is the nested
Private.Infrastructure.TestServices.WindowHelper, not a type in
Uno.UI.RuntimeTests.Helpers, and isn't a global using, so removing it
would break compilation.

Runtime-validated: passes on Skia Desktop.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01A9s2iUVnwJRRdpviweaTCR
@github-actions

github-actions Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 5m 19s —— View job


Review complete

  • Gather context (PR synchronized — test: Strengthen x:Bind OnNavigatedTo regression test)
  • Read current state of changed files
  • Check whether prior review findings are addressed
  • Post inline comments for remaining issues
  • Update summary comment

Summary

The test: Strengthen x:Bind OnNavigatedTo regression test commit addressed all four blocking/notable findings from the previous review round:

Prior finding Status
Bindings.Update() in DataContextChanged masks the bug ✅ Removed
Only asserts BoundText (backing property), not the rendered TextBlock.Text ✅ Fixed — now waits for and asserts TheTextBlock.Text
Task.Delay(200) unnecessary 200 ms cost ✅ Replaced with Task.Yield()
protected internal on OnNavigatedTo breaks WinUI builds ✅ Fixed with #if HAS_UNO conditional

Correction to previous review: The prior round incorrectly flagged using static Private.Infrastructure.TestServices; as unused. It is used — WindowHelper is a nested static class inside TestServices (in Private.Infrastructure), so the using static is required. The inverse is true: using Uno.UI.RuntimeTests.Helpers; is what appears unused here.

3 remaining minor issues flagged inline:

  1. using Uno.UI.RuntimeTests.Helpers; unused (line 4) — nothing from that namespace is referenced in this file; may trigger IDE0005 on analyzer-strict CI.
  2. using Microsoft.VisualStudio.TestTools.UnitTesting; redundant (line 3) — already a global using in GlobalUsings.cs; same IDE0005 risk.
  3. Missing try-finally cleanup (lines 25–27) — WindowHelper.WindowContent = frame is never reset in a finally block. If a WaitFor timeout fires, the Frame stays as window content and can contaminate subsequent tests. This is the most impactful remaining issue.

The regression test shape is correct: Task.Yield() before navigation creates the async break that triggers the original timing bug, and the test now verifies both the source property and the rendered TextBlock.Text without any Bindings.Update() workaround papering over it.

Validation evidence:

  • Code review assessment: issues identified above.
  • Compile validation: not run locally (CI-only environment).
  • Runtime validation: not run locally. PR author confirms the test passes on Skia; re-verify after applying the cleanup fix.

@unodevops

Copy link
Copy Markdown
Contributor

- Reset WindowHelper.WindowContent in a finally block so a WaitFor
  timeout can't leak the Frame into the next test.
- Drop the unused `using Uno.UI.RuntimeTests.Helpers;`.
- Drop the redundant `using Microsoft.VisualStudio.TestTools.UnitTesting;`
  (already a global using in GlobalUsings.cs).

Runtime-validated: passes on Skia Desktop.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01A9s2iUVnwJRRdpviweaTCR
@github-actions

github-actions Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 2m 25s —— View job


Review complete

  • Gather context (PR synchronized — test: Tidy x:Bind OnNavigatedTo test per second review)
  • Read current state of changed files
  • Check whether prior review findings are addressed
  • Post inline comments for remaining issues (none — all clear)
  • Update summary comment

Summary

The test: Tidy x:Bind OnNavigatedTo test per second review commit addressed all three minor issues flagged in the previous round:

Prior finding Status
using Uno.UI.RuntimeTests.Helpers; unused ✅ Removed
using Microsoft.VisualStudio.TestTools.UnitTesting; redundant (already a global using in GlobalUsings.cs) ✅ Removed
WindowHelper.WindowContent set but never reset in finally — can leak state into subsequent tests ✅ Fixed — try/finally now wraps the navigation + assertion block, resetting WindowContent = null on exit

No new issues found. The test is well-structured:

  • Task.Yield() creates the async-continuation break that reproduces the original timing bug.
  • No Bindings.Update() workaround — the test relies on x:Bind evaluating at the correct point in the lifecycle.
  • Asserts both the backing property (BoundText) and the rendered UI value (TheTextBlock.Text) via a WaitFor timeout, so a stale-UI regression is caught even if the property is correct.
  • try/finally ensures WindowHelper.WindowContent is always reset.
  • #if HAS_UNO on internal keeps the page building on both Uno and native WinUI targets.

Validation evidence:

  • Code review: all prior findings resolved; no new issues found by inspection.
  • Compile: not run locally (CI-only environment).
  • Runtime: PR author confirmed the test passes on Skia Desktop after the strengthening commit.

@MartinZikmund

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@unodevops

Copy link
Copy Markdown
Contributor

@MartinZikmund
MartinZikmund merged commit 8e1c93b into master Jun 24, 2026
46 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/repro/2872 branch June 24, 2026 13:49
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.

4 participants