fix(Navigation): Use NullLogger fallback with diagnostic warning and add documentation to prevent crash when Region.Attached is used in ExtendedSplashScreen (backport #2958) - #2968
Merged
Conversation
7 tasks
|
|
kazo0
enabled auto-merge
December 1, 2025 23:24
kazo0
approved these changes
Dec 1, 2025
kazo0
approved these changes
Dec 1, 2025
…enceException when Region.Attached is used before NavigationHostedService starts Co-authored-by: kazo0 <4793020+kazo0@users.noreply.github.com> (cherry picked from commit 53c151c)
…lization Co-authored-by: vatsashah45 <72754751+vatsashah45@users.noreply.github.com> (cherry picked from commit b76cfd2)
Co-authored-by: vatsashah45 <72754751+vatsashah45@users.noreply.github.com> (cherry picked from commit c4d3e26)
…d region initialization Co-authored-by: kazo0 <4793020+kazo0@users.noreply.github.com> (cherry picked from commit 37bcca2)
…content Co-authored-by: kazo0 <4793020+kazo0@users.noreply.github.com> (cherry picked from commit 55bf394)
Co-authored-by: kazo0 <4793020+kazo0@users.noreply.github.com> (cherry picked from commit 19e52c9)
(cherry picked from commit 9823831)
(cherry picked from commit f1c7fd4)
kazo0
force-pushed
the
mergify/bp/release/stable/7.0/pr-2958
branch
from
December 1, 2025 23:34
17f0856 to
98b48b5
Compare
kazo0
approved these changes
Dec 3, 2025
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 #2957
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Using
Region.Attached="True"inside anExtendedSplashScreencontent throwsNullReferenceException: "Logger needs to be set"because XAML parsing triggersAttachedChangedbeforeNavigationHostedService.StartAsyncinitializes the logger.What is the new behavior?
The navigation system already properly defers region initialization until services are available. When
Region.Attached="True"is encountered:NavigationRegionis created and hooks upViewLoading/ViewLoadedeventsAssignParentis called which looks for the service providerThe only missing piece was that
Region.Loggerwas accessed beforeNavigationHostedService.StartAsyncran, causing the crash. This fix:NullLogger<NavigationRegion>.Instanceas a fallback when the logger hasn't been set yetDebug.WriteLineexplaining the deferred initialization behaviorInterlocked.CompareExchangeto ensure the message only appears onceCode Changes:
Documentation Changes:
doc/Learn/Navigation/HowTo-Regions.mdthat explains whyRegion.Attached="True"should not be used insideExtendedSplashScreencontent, shows incorrect usage with a code example marked to avoid, and provides the correct approach with examples showing where to define regions instead.doc/Learn/Navigation/Walkthrough/DefineRegions.mdwarning developers not to useRegion.Attached="True"inside Shell.xaml or ExtendedSplashScreen content.This documentation will be available to the Uno Docs MCP and LLM agents to prevent them from generating code with this anti-pattern.
PR Checklist
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Runresults.Other information
The documentation added to both
HowTo-Regions.mdandWalkthrough/DefineRegions.mdserves as guidance for both developers and LLM/AI agents to avoid usingRegion.Attachedin Shell.xaml content, which is an anti-pattern that can cause initialization issues.Internal Issue (If applicable):
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
This is an automatic backport of pull request #2958 done by Mergify.