Skip to content

Conversation

@MackinnonBuck
Copy link
Member

@MackinnonBuck MackinnonBuck commented Aug 31, 2021

Fix root <PageTitle> not working when a default, static <title> is provided
There was an issue in which the root <PageTitle>, if rendered just after the application started, would not change the title of the page if a static <title> was provided in index.html. This PR fixes the issue.

PR Description
The problem arose because HeadOutlet wouldn't render the default title until it was determined from the statically-rendered title. This gave other <PageTitle> components the opportunity to render first, incorrectly serving as the default page title. When the true default title finally rendered, it took priority over the developer-provided <PageTitle> (which was rendered first), making it appear to have no effect.

I've added a new SectionContent parameter, IsDefaultContent. When true, the registered section content will take lower priority than all other existing content. This allows the HeadOutlet to ensure its own SectionContent for the default title will have the lowest priority.

An alternative I considered was to always render the SectionContent for the default title, but only render the <title> element when the default title is actually determined. This sometimes works, but it breaks in cases like prerendering because <PageTitle> elements in the "app" root component still get rendered first.

Fixes #35973

@MackinnonBuck MackinnonBuck requested a review from a team as a code owner August 31, 2021 18:10
@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Aug 31, 2021
@MackinnonBuck MackinnonBuck changed the title Fix root '<PageTitle>' not working when a default, static '<title>` is provided Fix root '<PageTitle>' not working when a default, static '<title>' is provided Aug 31, 2021
@MackinnonBuck MackinnonBuck requested a review from pranavkm August 31, 2021 18:23
[Parameter] public string Name { get; set; } = default!;

/// <summary>
/// Gets or sets whether this component should provide the default content for the target
Copy link
Contributor

@pranavkm pranavkm Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I mind this change - but what happens if we remove this property and treat it as it it were always true - given that there's only one thing that provides it today?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SectionContent is also used in PageTitle:

builder.OpenComponent<SectionContent>(0);

It doesn't specify IsDefaultContent because it's false for every case other than the default title, which is rendered by HeadOutlet.

Am I understanding the suggestion correctly?

@MackinnonBuck MackinnonBuck merged commit cc5f896 into main Sep 2, 2021
@MackinnonBuck MackinnonBuck deleted the t-mbuck/head-outlet-default-title-fix branch September 2, 2021 17:07
@ghost ghost added this to the 7.0-preview1 milestone Sep 2, 2021
@MackinnonBuck
Copy link
Member Author

/backport to release/6.0

@ghost
Copy link

ghost commented Sep 2, 2021

Hi @MackinnonBuck. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET 6, Preview 7: Setting title in WASM App

4 participants