aspnetcore: PageTitle doesn't display for SSR pages in mixed render mode app

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Info: Investigation shows that this is related to enhanced navigation and DOM preservation. See comment.

I have a Blazor Server app with mixed render modes, SSR and WebAssembly (Auto). Some pages are server-rendered, and a couple of them have dynamic components (WebAssembly Auto) that set the title depending on content.

In App.razor, I have added render mode to the HeadOutlet:

<HeadOutlet @rendermode="@RenderMode.Auto" />

Upon navigating to to a page, PageTitle is then only updated/rendered for the pages with dynamic components setting them, but not the server-side rendered pages.

They instead default to their address:

Screenshot 2023-08-22 at 20 26 52

The <title> element is not even rendered in <head></head>.

Expected Behavior

That PageTitle works in components of all modes a in mixed render mode app.

Even if HeadOutlet has the @rendermode="@RenderMode.Auto" the PageTitleof SSR pages should be rendered.

Steps To Reproduce

  1. Create a Blazor Server app.
  2. Update App.razor:
<HeadOutlet @rendermode="@RenderMode.Auto" />
  1. Create a page component which has a dynamic component that declares a PageTitle.

Exceptions (if any)

No response

.NET Version

8.0.100-rc.2.23421.3

Anything else?

No response

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

Parking this in the same milestone as https://github.com/dotnet/aspnetcore/issues/51132. Let’s see if we can actually solve the more general problem tracked by that issue, and if not, then try to solve the PageTitle case as a special one.

@marinasundstrom @MackinnonBuck Are you sure this has something to do with DOM preservation or enhanced nav? I don’t think it does, since the same issue will still occur even if you disable those via:

Blazor.start({
    ssr: { disableDomPreservation: true }
});

Instead, I think what happens is:

  • <HeadOutlet @rendermode=...> prerenders, emitting the correct title into the response
  • Then the interactive runtime starts and re-runs <HeadOutlet>
  • But if the current page is not interactive, then there is no <PageTitle> anywhere in the circuit/runtime, and so <HeadOutlet> updates the page’s title to nothing

So really I think this is an issue with interactive HeadOutlet believing that it should actively remove any existing title from the page if none was specified via PageTitle.