Skip to content

Commit

Permalink
Fix root '<PageTitle>' not working when a default, static '<title>' i…
Browse files Browse the repository at this point in the history
…s provided (dotnet#35982)
  • Loading branch information
MackinnonBuck authored Sep 2, 2021
1 parent c4d7d34 commit cc5f896
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/Components/Components/src/Sections/SectionContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ internal class SectionContent : ISectionContentProvider, IComponent, IDisposable
private SectionRegistry _registry = default!;

/// <summary>
/// Gets or sets the name that determines which <see cref="SectionOutlet"/> instances will render
/// Gets or sets the name that determines which <see cref="SectionOutlet"/> instance will render
/// the content of this instance.
/// </summary>
[Parameter] public string Name { get; set; } = default!;

/// <summary>
/// Gets or sets whether this component should provide the default content for the target
/// <see cref="SectionOutlet"/>.
/// </summary>
[Parameter] public bool IsDefaultContent { get; set; }

/// <summary>
/// Gets or sets the content to be rendered in corresponding <see cref="SectionOutlet"/> instances.
/// </summary>
Expand Down Expand Up @@ -45,7 +51,7 @@ Task IComponent.SetParametersAsync(ParameterView parameters)
_registry.RemoveProvider(_registeredName, this);
}

_registry.AddProvider(Name, this);
_registry.AddProvider(Name, this, IsDefaultContent);
_registeredName = Name;
}

Expand Down
11 changes: 9 additions & 2 deletions src/Components/Components/src/Sections/SectionRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ internal sealed class SectionRegistry
private readonly Dictionary<string, ISectionContentSubscriber> _subscribersByName = new();
private readonly Dictionary<string, List<ISectionContentProvider>> _providersByName = new();

public void AddProvider(string name, ISectionContentProvider provider)
public void AddProvider(string name, ISectionContentProvider provider, bool isDefaultProvider)
{
if (!_providersByName.TryGetValue(name, out var providers))
{
providers = new();
_providersByName.Add(name, providers);
}

providers.Add(provider);
if (isDefaultProvider)
{
providers.Insert(0, provider);
}
else
{
providers.Add(provider);
}
}

public void RemoveProvider(string name, ISectionContentProvider provider)
Expand Down
7 changes: 4 additions & 3 deletions src/Components/Web/src/Head/HeadOutlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenComponent<SectionContent>(2);
builder.AddAttribute(3, nameof(SectionContent.Name), TitleSectionOutletName);
builder.AddAttribute(4, nameof(SectionContent.ChildContent), (RenderFragment)BuildDefaultTitleRenderTree);
builder.AddAttribute(4, nameof(SectionContent.IsDefaultContent), true);
builder.AddAttribute(5, nameof(SectionContent.ChildContent), (RenderFragment)BuildDefaultTitleRenderTree);
builder.CloseComponent();
}

// Render the rest of the head metadata
builder.OpenComponent<SectionOutlet>(5);
builder.AddAttribute(6, nameof(SectionOutlet.Name), HeadSectionOutletName);
builder.OpenComponent<SectionOutlet>(6);
builder.AddAttribute(7, nameof(SectionOutlet.Name), HeadSectionOutletName);
builder.CloseComponent();
}

Expand Down

0 comments on commit cc5f896

Please sign in to comment.