Skip to content

[Blazor] Cascading RouteData in Layout causes OnInitializedAsync to be called twice when navigating to another LayoutΒ #20637

@Charnock

Description

@Charnock

Describe the bug

When navigating between pages with two different layouts, if the page you're navigating from has a CascadingParameter for RouteData, OnInitializedAsync will be called twice on the page you're navigating to.

To Reproduce

I've included a minimal repro here. I've added logging to OnInitializedAsync of the Index, Counter, and Fetch Data pages.

  • Start the project and navigate from the Index page to the Counter page.
  • Then navigate from Counter to either the Index or Fetch Data
  • Observe that OnInitializedAsync is called twice for Index or Fetch Data

This behavior does not occur when Navigating between Index and Fetch Data.

Additionally, I've commented out a second CascadingValue in App.razor which cascades a string. Uncommenting that CascadingValue appears to resolve the issue, even when that value isn't being used on any of the pages. Also, only using the cascading string doesn't appear to reproduce the issue.

Further technical details

.NET Core SDK (reflecting any global.json):
Version: 3.1.300-preview-015048
Commit: 13f19b4682

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.300-preview-015048\

Host (useful for support):
Version: 3.1.3
Commit: 4a9f85e9f8

Microsoft Visual Studio Community 2019
Version 16.5.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pillar: Technical DebtPriority:1Work that is critical for the release, but we could probably ship withoutaffected-fewThis issue impacts only small number of customersarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-blazor-builtin-componentsFeatures related to the built in components we ship or could ship in the futureseverity-minorThis label is used by an internal tool

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions