Skip to content

Commit d75ce04

Browse files
authored
Merge pull request #2958 from unoplatform/copilot/fix-logger-exception-splash-screen
fix(Navigation): Use NullLogger fallback with diagnostic warning and add documentation to prevent crash when Region.Attached is used in ExtendedSplashScreen
2 parents dea3b57 + f1c7fd4 commit d75ce04

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

doc/Learn/Navigation/HowTo-Regions.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,41 @@ A Region is used to link specific sectors of a view to individual items on a nav
1111
> [!NOTE]
1212
> If an app only uses basic navigation between pages without any nested views or pages, it is not necessary to register routes. In such cases, the default `Frame` and navigator are sufficient to manage the navigation, simplifying the setup and reducing the need for additional configuration.
1313
14+
## Avoid Using Region.Attached in Shell.xaml Content
15+
16+
When using the navigation extensions with an `ExtendedSplashScreen` in your `Shell.xaml`, do **not** add `Region.Attached="True"` to content inside the `ExtendedSplashScreen`. This includes any custom content you might want to add while the splash screen is loading.
17+
18+
**Incorrect Usage (Avoid This):**
19+
20+
```xml
21+
<utu:ExtendedSplashScreen x:Name="Splash">
22+
<!-- DO NOT add Region.Attached here - navigation host is not ready yet -->
23+
<Grid uen:Region.Attached="True"
24+
uen:Region.Navigator="Visibility">
25+
<!-- This will cause initialization issues -->
26+
</Grid>
27+
</utu:ExtendedSplashScreen>
28+
```
29+
30+
**Why:** The `Region.Attached` property triggers navigation region initialization, which requires the navigation host (and its dependency injection container) to be fully started. During `Shell.xaml` construction, the host is not yet ready, leading to initialization issues.
31+
32+
**Correct Approach:** The navigation system handles the initial navigation automatically from the Shell to your initial page. You don't need to manually add region-attached content inside the `ExtendedSplashScreen`. Instead, define your regions on your actual pages (like `MainPage`) where the navigation host is fully initialized.
33+
34+
```xml
35+
<!-- Shell.xaml - Keep ExtendedSplashScreen content simple -->
36+
<utu:ExtendedSplashScreen x:Name="Splash">
37+
<!-- Only use loading indicators, no Region.Attached content -->
38+
</utu:ExtendedSplashScreen>
39+
40+
<!-- MainPage.xaml - Define regions here instead -->
41+
<Page>
42+
<Grid uen:Region.Attached="True"
43+
uen:Region.Navigator="Visibility">
44+
<!-- Navigation content works correctly here -->
45+
</Grid>
46+
</Page>
47+
```
48+
1449
## Properties in the Region Class
1550

1651
1. **`Region.Attached`**:

doc/Learn/Navigation/Walkthrough/DefineRegions.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ tags: [uno, uno-platform, uno-extensions, navigation, regions, Region.Attached,
66

77
# Navigate between regions inside the same page (Region-based navigation)
88

9+
> [!IMPORTANT]
10+
> **Do not use `Region.Attached="True"` inside Shell.xaml or ExtendedSplashScreen content.** The navigation host is not ready during Shell construction. Define regions on your actual pages (like `MainPage`) instead.
11+
912
## Link navigation control with content using regions
1013

1114
```xml

src/Uno.Extensions.Navigation.UI/Region.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Uno.Extensions.Navigation.Regions;
1+
using System.Diagnostics;
2+
using Microsoft.Extensions.Logging.Abstractions;
3+
using Uno.Extensions.Navigation.Regions;
24

35
namespace Uno.Extensions.Navigation.UI;
46

@@ -8,7 +10,12 @@ namespace Uno.Extensions.Navigation.UI;
810
public static class Region
911
{
1012
private static ILogger? _logger;
11-
internal static ILogger Logger { get => _logger ?? throw new NullReferenceException("Logger needs to be set"); set => _logger = value; }
13+
14+
internal static ILogger Logger
15+
{
16+
get => _logger ?? NullLogger<NavigationRegion>.Instance;
17+
set => _logger = value;
18+
}
1219

1320
public static readonly DependencyProperty InstanceProperty =
1421
DependencyProperty.RegisterAttached(

0 commit comments

Comments
 (0)