aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

RequestId flashed across the page

Open Varorbc opened this issue 1 year ago • 4 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Describe the bug

RequestId flashed across the page

Expected Behavior

No response

Steps To Reproduce

  1. dotnet new blazor -ai
  2. dotnet run
  3. navigation to error page

Exceptions (if any)

No response

.NET Version

9.0.100-rc.1.24452.12

Anything else?

No response

Varorbc avatar Oct 15 '24 06:10 Varorbc

@Varorbc thanks for contacting us.

That's been the behavior since 8.0. What's happening is that the page becomes interactive and at that point the requestId is not available. The way to handle this is to check the metadata on the App.razor component and render it statically.

javiercn avatar Oct 15 '24 09:10 javiercn

Moving this to the backlog in case we decide to make improvements to the template.

javiercn avatar Oct 15 '24 09:10 javiercn

That's been the behavior since 8.0.

@javiercn I noticed it works great on 8.0, but there's an issue only in 9.0

Varorbc avatar Oct 15 '24 09:10 Varorbc

@javiercn I'm really curious why it's running twice. The first time it runs, Activity.Current is available, but the second time it's not, which causes the RequestId to show up and then disappear right away.

Varorbc avatar Oct 16 '24 08:10 Varorbc

This only happens when navigating to the page, not when an actual error is triggered.

When an error is triggered, we always render statically, but if you navigate and have global interactivity, then the page will first render, then interactivity will start and re-render (hence the flashing).

Couple of ways to deal with this:

  • Using `[PersistentState] to just persist the original TraceId. It will get rid of the flashing.
  • Use https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-9.0#static-ssr-pages-in-an-interactive-app on the template code.

Separately, we should consider updating the Error page to use the Activity associated with the component host (that would work for server/client/SSR)

javiercn avatar Sep 06 '25 09:09 javiercn