Closed
fix: Complete ForResult navigation when SystemNavigationManager.BackRequested fires#2951
Conversation
… for all platforms This change addresses a race condition where NavigateForResult calls would never complete if the user pressed the back button (via NavigationBar from Toolkit) before the page's DataContext finished loading. The fix hooks up SystemNavigationManager.BackRequested in ResponseNavigator for all platforms (not just WASM), ensuring that when back navigation occurs during a ForResult navigation, the TaskCompletionSource properly completes with None, preventing the UI from getting stuck. Co-authored-by: kazo0 <4793020+kazo0@users.noreply.github.com>
|
|
Copilot
AI
changed the title
[WIP] Fix navigation race condition with NavigateForResult
fix: Complete ForResult navigation when SystemNavigationManager.BackRequested fires
Nov 19, 2025
kazo0
marked this pull request as ready for review
November 19, 2025 18:01
Contributor
|
@copilot can you add some tests for this scenario? |
- Added ResponseNavigatorTests.cs with unit test documentation - Created ForResult UI test scenario with two pages - ForResultSecondPage has NavigationBar with back button and simulates heavy init - UI tests validate that ForResult completes when BackRequested fires - Added test section Navigation_ForResult to TestSections enum - Tests verify both race condition fix and normal ForResult behavior Co-authored-by: kazo0 <4793020+kazo0@users.noreply.github.com>
Added explicit 'using Windows.UI.Core;' to ResponseNavigator.cs to resolve build error. SystemNavigationManager is in the Windows.UI.Core namespace, which is only included globally for non-WINUI platforms. Co-authored-by: kazo0 <4793020+kazo0@users.noreply.github.com>
Contributor
Author
Added comprehensive tests in commit 45cc8c0: Unit Tests (
UI Tests (
Test Infrastructure:
The tests validate that when SystemNavigationManager.BackRequested fires (via NavigationBar back button), the ForResult task completes with Option.None instead of hanging indefinitely. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GitHub Issue (If applicable): closes #2905
PR Type
What is the current behavior?
NavigateViewModelForResultAsyncand similar ForResult methods hang indefinitely if back navigation occurs viaSystemNavigationManager.BackRequested(e.g., pressing NavigationBar back button from Toolkit) before the target page's DataContext completes initialization. The awaited call never returns, leaving UI stuck.SystemNavigationManager.BackRequestedwas only monitored inBackButtonServicefor WebAssembly. However, Toolkit's NavigationBar raises this event on all platforms, creating a race condition where back navigation bypassesResponseNavigator's completion logic.What is the new behavior?
ResponseNavigator<TResult>now subscribes toSystemNavigationManager.BackRequestedon all platforms:Option.None<TResult>()when firede.Handled, allowingBackButtonServiceto process navigationApplyResultto prevent memory leaksForResult navigations now complete correctly when back is pressed before page initialization, regardless of timing.
PR Checklist
Screenshots Compare Test Runresults.Other information
Modified Files:
src/Uno.Extensions.Navigation.UI/ResponseNavigator.csusing Windows.UI.Core;for SystemNavigationManager_systemNavigationManagerfieldBackRequestedevent in constructor/ApplyResultOnSystemBackRequestedhandler completes task with NoneTests Added:
src/Uno.Extensions.Navigation.Tests/ResponseNavigatorTests.cstesting/TestHarness/TestHarness/Ext/Navigation/ForResult/*(6 files)testing/TestHarness/TestHarness.UITest/Ext/Navigation/ForResult/Given_ForResult.csWhen_BackPressed_During_ForResult_Navigation_Should_Complete: Validates race condition fixWhen_NormalReturn_With_ForResult_Should_Return_Value: Validates normal ForResult behaviortesting/TestHarness/TestHarness.Core/TestSections.csInternal Issue (If applicable): N/A
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.