Skip to content

Commit 77da59b

Browse files
Make it irrelevant whether components call base.BuildRenderTree or not. Fixes #8192
1 parent 341cd25 commit 77da59b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/Components/Components/src/ComponentBase.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ namespace Microsoft.AspNetCore.Components
2525
/// </summary>
2626
public abstract class ComponentBase : IComponent, IHandleEvent, IHandleAfterRender
2727
{
28-
/// <summary>
29-
/// Specifies the name of the <see cref="RenderTree"/>-building method.
30-
/// </summary>
31-
public const string BuildRenderTreeMethodName = nameof(BuildRenderTree);
32-
3328
private readonly RenderFragment _renderFragment;
3429
private RenderHandle _renderHandle;
3530
private bool _initialized;
@@ -41,7 +36,12 @@ public abstract class ComponentBase : IComponent, IHandleEvent, IHandleAfterRend
4136
/// </summary>
4237
public ComponentBase()
4338
{
44-
_renderFragment = BuildRenderTree;
39+
_renderFragment = builder =>
40+
{
41+
_hasPendingQueuedRender = false;
42+
_hasNeverRendered = false;
43+
BuildRenderTree(builder);
44+
};
4545
}
4646

4747
/// <summary>
@@ -52,8 +52,9 @@ protected virtual void BuildRenderTree(RenderTreeBuilder builder)
5252
{
5353
// Developers can either override this method in derived classes, or can use Razor
5454
// syntax to define a derived class and have the compiler generate the method.
55-
_hasPendingQueuedRender = false;
56-
_hasNeverRendered = false;
55+
56+
// Other code within this class should *not* invoke BuildRenderTree directly,
57+
// but instead should invoke the _renderFragment field.
5758
}
5859

5960
/// <summary>

0 commit comments

Comments
 (0)