Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Navigation stack of NavigationPage corrupted after PopAsync with modal page visible on iOS #14551

Open
cpraehaus opened this issue Aug 30, 2021 · 3 comments
Labels
a/navigation p/iOS 🍎 s/unverified New report that has yet to be verified t/bug 🐛

Comments

@cpraehaus
Copy link
Contributor

Description

We are using NavigationPage to show our MainPage as root page. At some point in our application we want to switch from a non-modal page (Page1) - that was pushed on the nav. stack - to a modal page (Page2), so that when the user navigates back (closes the modal page) he comes back to the main page (and not to Page1).

But this sequence of nav. operations described in repro below causes the navigation stack to get corrupted on iOS, producing different kinds of follow-up errors. On Android everything works perfectly.

The problem is that the implementation of PopAsync on iOS removes the Page from the visual stack and waits for page visibility events (disappearing) which it does not get immediately since the modal stack is active showing Page2 and hiding Page1.

Now PopAsync(Page1) waits for page disappearing event (unfortunately using a very poor implementation which waits for multiple event types and so also receives appearing event).

26320525-ca75-414a-af91-711f0f1cde82

When modal page (Page2) is removed/closed an appearing event followed by a disappearing event is generated for (non-modal) page Page1. Thereby the first PopAsync is unblocked but sees that it received appearing event and not disappearing as it would have expected (see iOS.NavigationRenderer.OnPopViewAsync) . So it considers the removal failed (sets actuallyRemoved to false) and PopAsync will then not remove Page1 from nav stack. But actually the page IS REMOVED and not visible anymore, so the nav stack is corrupted and following nav actions will certainly fail at some point.

Steps to Reproduce

  1. Push non-modal Page1 on nav stack using PushAsync
  2. Push modal page Page2 on modal stack using PushModalAsync
  3. Pop Page1 from nav stack while modal Page2 is visible using PopAsync
  4. Close modal page Page2 using PopModalAsync
  5. PopAsync removed page from visual stack but does not remove it form nav stack, resulting in corrupted nav stack.
  6. Due to corrupted nav stack further NavigationPage operations will eventually fail

Expected Behavior

Page1 is removed from visual stack and from (non-modal) navigation stack Navigation.NavigationStack leaving nav. stack in consistent state.

Actual Behavior

Page1 is removed from visual stack but not from (non-modal) navigation stack Navigation.NavigationStack leaving nav. stack in inconsistent state.

Basic Information

  • Version with issue: 4.8.0.1821, 5.0.0.2083 and maybe earlier versions as well
  • Last known good version: ?
  • Platform Target Frameworks:
    • iOS: 11.0

Environment

Not relevant.

Build Logs

Not relevant.

Screenshots

Not relevant.

Reproduction Link

Sandbox_NavStackCorruptAfterPop.zip

Run Xamarin.Forms.Sandbox.iOS. Click the buttons until you receive the error dialog.

Workaround

No workaround.

@cpraehaus cpraehaus added s/unverified New report that has yet to be verified t/bug 🐛 labels Aug 30, 2021
@arda-a
Copy link

arda-a commented Jan 5, 2023

I have exactly the same issue. Have you been able to find a workaround for this ?

@cpraehaus
Copy link
Contributor Author

@arda-a No, we don't have a work-around. In our case (we have a navigation service wrapping the NavigationPage) we ended up avoiding the that the situation arises by deferring the PopAsync until the modal stack is empty again.

@arda-a
Copy link

arda-a commented Jan 9, 2023

Thanks very much for the response. I ended up doing the same.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/navigation p/iOS 🍎 s/unverified New report that has yet to be verified t/bug 🐛
Projects
None yet
Development

No branches or pull requests

3 participants