Skip to content

Conversation

@Vignesh-SF3580
Copy link
Contributor

@Vignesh-SF3580 Vignesh-SF3580 commented Mar 27, 2025

Issue Detail

The NavigationStack was not updated when OnAppearing was invoked.

Root Cause

The OnAppearing event was triggered before the popped page was removed from the stack in the RemoveAsyncInner method. This method is triggered on iOS when popping pages.

Description of Change

Triggering the OnAppearing event after updating the stack resolves the issue.

Tested the behavior in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #28414

Screenshots

Before Issue Fix After Issue Fix
28414Before.mov
28414After.mov

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Mar 27, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@Vignesh-SF3580 Vignesh-SF3580 marked this pull request as ready for review March 28, 2025 13:41
Copilot AI review requested due to automatic review settings March 28, 2025 13:41
@Vignesh-SF3580 Vignesh-SF3580 requested a review from a team as a code owner March 28, 2025 13:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where the NavigationStack was not correctly updated on iOS when the OnAppearing event was triggered. The changes include:

  • Reordering the FireAppearing call in NavigationPage.Legacy.cs to occur after the page is removed from the stack.
  • Adding corresponding tests in both TestCases.Shared.Tests and TestCases.HostApp to verify the updated navigation behavior.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28414.cs Adds a test verifying the NavigationStack count after a page pop.
src/Controls/tests/TestCases.HostApp/Issues/Issue28414.cs Sets up pages and navigation steps to validate the OnAppearing behavior.
src/Controls/src/Core/NavigationPage/NavigationPage.Legacy.cs Adjusts the logic for firing the OnAppearing event after removing a page.

Copy link
Contributor

@bhavanesh2001 bhavanesh2001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems MemortyTests which use PopAsync() have failed and some other related UITests are also failed

Screenshot 2025-03-26 at 10 59 15 PM
System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')

More info...

@Vignesh-SF3580
Copy link
Contributor Author

Seems MemortyTests which use PopAsync() have failed and some other related UITests are also failed

Screenshot 2025-03-26 at 10 59 15 PM ```cs System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index') ```

More info...

@bhavanesh2001 I have updated the code changes to resolve the test case failures.

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@MitchBomcanhao
Copy link

build seems a bit stuck?

@rmarinho rmarinho added this to the .NET 9 SR7 milestone Apr 11, 2025
@rmarinho rmarinho moved this from Todo to Ready To Review in MAUI SDK Ongoing Apr 11, 2025
@MitchBomcanhao
Copy link

this needs re-running as the pipeline agents got disconnected

@MitchBomcanhao
Copy link

nobody? @jsuarezruiz

@MitchBomcanhao
Copy link

@rmarinho ?

@bhavanesh2001
Copy link
Contributor

@MitchBomcanhao I think the pipelines will be run if someone reviewing this feels it’s necessary. It's possible the team is currently busy with other PRs.

@MitchBomcanhao
Copy link

MitchBomcanhao commented Apr 22, 2025

they tried to run it once and it hasn't worked. they've been ignoring it since... the build agent failed, the build needs to be triggered again. it isn't much effort for someone to stop this and trigger it again. nobody is that busy. this PR possibly fixes an important issue for us and to see it be ignored is quite disconcerting.

@github-project-automation github-project-automation bot moved this from Ready To Review to Changes Requested in MAUI SDK Ongoing Apr 23, 2025
@karthikraja-arumugam karthikraja-arumugam moved this from Changes Requested to Ready To Review in MAUI SDK Ongoing Apr 23, 2025
@karthikraja-arumugam karthikraja-arumugam moved this from Ready To Review to Changes Requested in MAUI SDK Ongoing Apr 23, 2025
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PureWeen PureWeen modified the milestones: .NET 9 SR9, .NET 9 SR10 Jul 3, 2025
@MitchBomcanhao
Copy link

bump

@MitchBomcanhao
Copy link

nobody?

@MitchBomcanhao
Copy link

bump

@PureWeen PureWeen modified the milestones: .NET 9 SR10, .NET 9 SR12 Aug 4, 2025
@MitchBomcanhao
Copy link

hello?

@PureWeen
Copy link
Member

/rebase

@PureWeen PureWeen requested a review from jsuarezruiz August 20, 2025 18:58
@PureWeen PureWeen changed the base branch from main to inflight/current August 20, 2025 18:59
Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to use a unit test vs a UITest? Since this is all xplat code we should be able to reproduce inside a test

@github-project-automation github-project-automation bot moved this from Changes Requested to Approved in MAUI SDK Ongoing Aug 20, 2025
@PureWeen PureWeen merged commit 39efbe3 into dotnet:inflight/current Aug 20, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Aug 20, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR12, .NET 9 SR11 Aug 20, 2025
github-actions bot pushed a commit that referenced this pull request Aug 22, 2025
…28666)

* Fixed - 28414 : iOS] Popping a page includes in the NavigationStack when the OnAppearing method is called

* updated NavigationPage.Legacy.cs

* Updated NavigationPage.Legacy.cs
jfversluis pushed a commit that referenced this pull request Aug 25, 2025
…28666)

* Fixed - 28414 : iOS] Popping a page includes in the NavigationStack when the OnAppearing method is called

* updated NavigationPage.Legacy.cs

* Updated NavigationPage.Legacy.cs
jfversluis added a commit that referenced this pull request Aug 28, 2025
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

### Issue Details
In the failed test
`AppDoesntCrashWhenSettingNewTitleViewOnExistingPage`, the TitleView was
updated in the OnAppearing method. When popping the page using PopAsync,
the OnAppearing event is triggered twice with my fix, whereas previously
it was triggered only once: once from
[FireAppearing](https://github.com/dotnet/maui/blob/b2c3452f68298f407ca18f8fe9e0f8841e7c9cad/src/Controls/src/Core/NavigationPage/NavigationPage.Legacy.cs#L67)
and once from
[CurrentPageChanged](https://github.com/dotnet/maui/blob/b2c3452f68298f407ca18f8fe9e0f8841e7c9cad/src/Controls/src/Core/NavigationPage/NavigationPage.Legacy.cs#L70).
This additional trigger causes the title to mismatch the expected value,
resulting in the test failure.

### Root Cause
The fix moves FireAppearing to after RemoveFromInnerChildren(page), but
at that point InternalChildren.Last() has already changed. Currently,
StackDepth - 2 is calculated based on the original stack depth. Once the
popped page is removed from stack, accessing InternalChildren[StackDepth
- 2] is not valid.

### Description of Change
Remove the page first, then use InternalChildren.Last(); directly to get
the correct page that should appear.

Regressed PR: #28666

Fixes AppDoesntCrashWhenSettingNewTitleViewOnExistingPage test failure
in PR: #31327

### Screenshots

<img width="540" height="300" alt="image"
src="https://github.com/user-attachments/assets/9dfaed05-0b66-489b-9b81-9a285088cc96"
/>
<img width="540" height="300" alt="image"
src="https://github.com/user-attachments/assets/81626605-6567-4a30-b183-d26513d5f60c"
/>
<img width="540" height="300" alt="image"
src="https://github.com/user-attachments/assets/260ca192-4baa-45e2-9991-8abcdadb2961"
/>
github-actions bot pushed a commit that referenced this pull request Sep 4, 2025
…28666)

* Fixed - 28414 : iOS] Popping a page includes in the NavigationStack when the OnAppearing method is called

* updated NavigationPage.Legacy.cs

* Updated NavigationPage.Legacy.cs
github-actions bot pushed a commit that referenced this pull request Sep 5, 2025
…28666)

* Fixed - 28414 : iOS] Popping a page includes in the NavigationStack when the OnAppearing method is called

* updated NavigationPage.Legacy.cs

* Updated NavigationPage.Legacy.cs
@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-navigation NavigationPage community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[iOS] Popping a page includes an unexpected page in the NavigationStack when the underlying page's OnAppearing method is called

6 participants