Skip to content

Commit 77a2bda

Browse files
Fixed race condition for default page title (#36099)
Co-authored-by: Mackinnon Buck <[email protected]>
1 parent ad18832 commit 77a2bda

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/Components/Components/src/Sections/SectionContent.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ internal class SectionContent : ISectionContentProvider, IComponent, IDisposable
1212
private SectionRegistry _registry = default!;
1313

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

20+
/// <summary>
21+
/// Gets or sets whether this component should provide the default content for the target
22+
/// <see cref="SectionOutlet"/>.
23+
/// </summary>
24+
[Parameter] public bool IsDefaultContent { get; set; }
25+
2026
/// <summary>
2127
/// Gets or sets the content to be rendered in corresponding <see cref="SectionOutlet"/> instances.
2228
/// </summary>
@@ -45,7 +51,7 @@ Task IComponent.SetParametersAsync(ParameterView parameters)
4551
_registry.RemoveProvider(_registeredName, this);
4652
}
4753

48-
_registry.AddProvider(Name, this);
54+
_registry.AddProvider(Name, this, IsDefaultContent);
4955
_registeredName = Name;
5056
}
5157

src/Components/Components/src/Sections/SectionRegistry.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ internal sealed class SectionRegistry
88
private readonly Dictionary<string, ISectionContentSubscriber> _subscribersByName = new();
99
private readonly Dictionary<string, List<ISectionContentProvider>> _providersByName = new();
1010

11-
public void AddProvider(string name, ISectionContentProvider provider)
11+
public void AddProvider(string name, ISectionContentProvider provider, bool isDefaultProvider)
1212
{
1313
if (!_providersByName.TryGetValue(name, out var providers))
1414
{
1515
providers = new();
1616
_providersByName.Add(name, providers);
1717
}
1818

19-
providers.Add(provider);
19+
if (isDefaultProvider)
20+
{
21+
providers.Insert(0, provider);
22+
}
23+
else
24+
{
25+
providers.Add(provider);
26+
}
2027
}
2128

2229
public void RemoveProvider(string name, ISectionContentProvider provider)

src/Components/Web/src/Head/HeadOutlet.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
4545
{
4646
builder.OpenComponent<SectionContent>(2);
4747
builder.AddAttribute(3, nameof(SectionContent.Name), TitleSectionOutletName);
48-
builder.AddAttribute(4, nameof(SectionContent.ChildContent), (RenderFragment)BuildDefaultTitleRenderTree);
48+
builder.AddAttribute(4, nameof(SectionContent.IsDefaultContent), true);
49+
builder.AddAttribute(5, nameof(SectionContent.ChildContent), (RenderFragment)BuildDefaultTitleRenderTree);
4950
builder.CloseComponent();
5051
}
5152

5253
// Render the rest of the head metadata
53-
builder.OpenComponent<SectionOutlet>(5);
54-
builder.AddAttribute(6, nameof(SectionOutlet.Name), HeadSectionOutletName);
54+
builder.OpenComponent<SectionOutlet>(6);
55+
builder.AddAttribute(7, nameof(SectionOutlet.Name), HeadSectionOutletName);
5556
builder.CloseComponent();
5657
}
5758

0 commit comments

Comments
 (0)