dotnet / dotnet/aspnetcore

Blazor WASM: page is instantiated twice when navigating between pages with different layouts

Open
#68,004 3 comments 1 reaction 0 assignees View on GitHub
area-blazor investigate
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

[recollections-layout-instantiation-poc.zip](https://github.com/user-attachments/files/30462998/recollections-layout-instantiation-poc.zip)

### Describe the bug

A minimal Blazor WebAssembly repro shows the target page being instantiated twice (two distinct instance IDs and duplicate lifecycle events) when navigating between pages that resolve to different layout types.

### Repro project

ZIP attachment URL will be added in a follow-up comment.

### To Reproduce

1. `dotnet tool restore`
2. `dotnet run --project src/Recollections.Blazor.LayoutInstantiation.Poc/Recollections.Blazor.LayoutInstantiation.Poc.csproj`
3. Open `http://localhost:5023`
4. Navigate repeatedly between **Default layout page** (`/`) and **Head layout page** (`/second-layout`)
5. Observe lifecycle trace in UI or browser console

### Expected behavior

One page instance should be created per navigation.

### Actual behavior

On each cross-layout navigation, two page instances are created (different IDs) and one is disposed immediately after first render.

### Additional context

The sample logs constructor and lifecycle calls with per-instance IDs so duplicate instantiation is obvious.

Contributor guide

Open the contributing guide

Research direction

Start with the attached repro project at src/Recollections.Blazor.LayoutInstantiation.Poc/Recollections.Blazor.LayoutInstantiation.Poc.csproj: run dotnet tool restore and dotnet run --project ... . Navigate repeatedly between / and /second-layout, then inspect the UI or browser-console lifecycle trace. Done means cross-layout navigation creates one page instance per navigation, without an immediately disposed duplicate.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, wasm
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.