[inflight/candidate] [Android] Fix Shell singleton page rendering blank when re-pushed after absolute route reset - #37113
Merged
kubaflo merged 1 commit intoAug 5, 2026
Conversation
…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: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
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.
Backport of #36903 to inflight/candidate
/cc @kubaflo @HarishwaranVijayakumar