Skip to content

[8.0.100-preview.4.23211.1] Page doesn't show passed content when using NavigationManager.NavigateTo() #47683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
Junjun-zhao opened this issue Apr 13, 2023 · 5 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@Junjun-zhao
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In dotnet-sdk-8.0.100-preview.4.23211.1, when using NavigationManager.NavigateTo() method to navigate to a page with parameter, the content from parameter doesn't appear on navigated page.

Expected Behavior

It navigates to "https://localhost:7016/counter/test" and the @data1 content appear on the page.

Steps To Reproduce

Repro steps:

1.Create a default Blazor Server app with Visual Studio.
2. Add following code on Counter.razor page.

@page "/counter"
@page "/counter/{param1}"
@inject NavigationManager Nav

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>
<p>@data1</p>
<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

<a href="#" @onclick="@(() => Nav.NavigateTo($"counter/test"))">test link</a>
@code {
    private int currentCount = 0;
    private string data1 = string.Empty;
    [Parameter] public string? param1 { get; set; }
    private void IncrementCount()
    {
        currentCount++;
    }
    protected override void OnInitialized()
    {
        if (!string.IsNullOrEmpty(param1))
        {
            data1 = param1;
        }
    }
}
  1. Build the project.
  2. Open the runtimeconfig.json file to change the runtime version to let the app run against 8.0.100-preview.4.23211.1:
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "8.0.0-preview.4.23210.1"
      },
      {
        "name": "Microsoft.AspNetCore.App",
        "version": "8.0.0-preview.4.23207.6"
      }
]
  1. Launch the app.
  2. Navigate to Counter page.
  3. Click the "test link".

Actual Result:
It navigates to "https://localhost:7016/counter/test" but the @data1 content doesn't show on the page.

Exceptions (if any)

No response

.NET Version

8.0.100-preview.4.23211.1

Anything else?

Findings

  1. When adding a breaking point on line of "if (!string.IsNullOrEmpty(param1))" to debug the demo: In 8.0.100-preview.4.23211.1, when clicking the "test link", the breaking point won't be hit. It seems the page OnInitialized method doesn't be triggered. In previous version, when clicking the "test link", the breaking point will be hit.

  2. The symptom is similar with bug [8.0.100-preview.4.23211.1] Anchor tag behavior changed when setting herf="#" in blazor app #47682

@dotnet-actwx-bot @dotnet/compat

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Apr 13, 2023
@surayya-MS
Copy link
Member

Thanks for the report @Junjun-zhao !

This is an expected behavior that was introduced recently.

This is what is happening:

Expected Behavior
It navigates to "https://localhost:7016/counter/test" and the @data1 content appear on the page.

Before this was working because first it was navigating to "/#" (base page) and then to "/counter/test" and OnInitialized was called.

With new behavior when clicking test link first it navigates to "/counter#" because of the href="#" (stays on the same page) then it navigates to "/counter/test" and this is the same page and OnInitialized is not called.

@Junjun-zhao
Copy link
Member Author

@surayya-MS
Thanks for your explanation. Is there a breaking change document for this change?

@surayya-MS
Copy link
Member

@surayya-MS Thanks for your explanation. Is there a breaking change document for this change?

No, not yet.

@Junjun-zhao
Copy link
Member Author

@surayya-MS Thank you for your reply. Could you please share the breaking change link when it is created? We will communicate it with App owners about this change.

.NET breaking changes are published on https://learn.microsoft.com/en-us/dotnet/core/compatibility/8.0 and template for breaking changes is here

PS: We are the .NET AppCompat team and have a representative set of apps in our lab, 2 apps affected by this change till now, it potentially impacts a bigger customer base in the real world.

@Junjun-zhao
Copy link
Member Author

 Verified it and the issue is fixed on dotnet-sdk-8.0.100-preview.4.23253.2

@ghost ghost locked as resolved and limited conversation to collaborators Jun 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

2 participants