Skip to content

[inflight/candidate] [Android] Fix Shell singleton page rendering blank when re-pushed after absolute route reset - #37113

Merged
kubaflo merged 1 commit into
inflight/candidatefrom
backport/pr-36903-to-inflight/candidate
Aug 5, 2026
Merged

[inflight/candidate] [Android] Fix Shell singleton page rendering blank when re-pushed after absolute route reset#37113
kubaflo merged 1 commit into
inflight/candidatefrom
backport/pr-36903-to-inflight/candidate

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Backport of #36903 to inflight/candidate

/cc @kubaflo @HarishwaranVijayakumar

…er absolute route reset (#36903)

<!-- 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!
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details:

- A DI-singleton page in Shell navigation renders blank when re-pushed
after a GoToAsync("///MainPage") stack reset.

### Root Cause of the issue

- PR #[35476](#35476) moved
page.DisconnectHandlers() into RemovePage() , which runs on all pop
paths including PopToRoot. This permanently destroys the handler for
singleton pages. On Android, a pre-existing bug in RemoveAllPushedPages
compounds this — it checks shellSection.Stack.Count which is already 1
by the time the platform event fires, so it early-returns and never
removes stale fragments from _fragmentMap . On re-push, the old fragment
is reused without calling OnCreateView , resulting in a blank page since
the handler is null.

**Why It Only Affects Singletons**

- Transient pages get a new instance each push → new fragment → renders
fine. Singleton pages reuse the same instance → old stale fragment found
→ no OnCreateView → blank.

### Description of Change

### Bug Fix: Fragment Removal Logic

* Improved the logic in `RemoveAllPushedPages` in
`ShellItemRendererBase.cs` to ensure that fragment transactions are only
committed if any fragments were actually removed, preventing issues
where singleton pages could render blank after navigation.

### New Test Case for Regression

* Added a new test page and scenario in `Issue36853.cs` (HostApp) to
reproduce the bug: navigating Root → SecondPage (singleton) → ThirdPage
→ PopToRoot → re-push SecondPage, which previously resulted in a blank
screen.
* Registered `Issue36853SecondPage` as a singleton and
`Issue36853ThirdPage` as transient in the DI container, matching the
real-world bug scenario.
[[1]](diffhunk://#diff-70f90c4c40092b9b58b067b769ce0a5ad5db3b0a8a72359fd7b816a682ad181bR1-R111)
[[2]](diffhunk://#diff-d01e2392fa68bd429a87ca25ef57d4ad83147746e650291c69f97c197d92628dL44-R45)

### Automated UITest

* Introduced an automated UITest in
`TestCases.Shared.Tests/Tests/Issues/Issue36853.cs` to verify that after
PopToRoot and re-pushing the singleton page, its content is visible and
not blank.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36853 

### Tested the behavior in the following platforms
 
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Output
 
| Before | After |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/bb4201ac-5be1-4553-8f34-2b4f4556dfd9">
| <video
src="https://github.com/user-attachments/assets/de6b0981-26d4-4c79-9490-9f1c65e17f92">
|








<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@kubaflo
kubaflo merged commit a75894b into inflight/candidate Aug 5, 2026
1 of 10 checks passed
@kubaflo
kubaflo deleted the backport/pr-36903-to-inflight/candidate branch August 5, 2026 13:00
@github-actions github-actions Bot added this to the .NET 10 SR10 milestone Aug 5, 2026
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.

2 participants