Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class BootstrapBlazorErrorBoundary : ErrorBoundaryBase
/// <param name="exception"></param>
protected override Task OnErrorAsync(Exception exception)
{
if (EnableILogger)
if (EnableILogger && Logger.IsEnabled(LogLevel.Error))
{
Logger.LogError(exception, "BootstrapBlazorErrorBoundary OnErrorAsync log this error occurred at {Page}", NavigationManager.Uri);
}
Expand Down
23 changes: 14 additions & 9 deletions src/BootstrapBlazor/Components/ErrorLogger/ErrorLogger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
Expand Down Expand Up @@ -101,15 +101,20 @@ protected override async Task OnInitializedAsync()
/// <param name="builder"></param>
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenComponent<CascadingValue<IErrorLogger>>(0);
builder.AddAttribute(1, nameof(CascadingValue<>.Value), this);
builder.AddAttribute(2, nameof(CascadingValue<>.IsFixed), true);
builder.AddAttribute(3, nameof(CascadingValue<>.ChildContent), RenderContent);
builder.CloseComponent();
if (EnableErrorLogger)
{
builder.OpenComponent<CascadingValue<IErrorLogger>>(0);
builder.AddAttribute(1, nameof(CascadingValue<>.Value), this);
builder.AddAttribute(2, nameof(CascadingValue<>.IsFixed), true);
builder.AddAttribute(3, nameof(CascadingValue<>.ChildContent), RenderError);
builder.CloseComponent();
}
else
{
builder.AddContent(10, ChildContent);
}
Comment on lines +104 to +115
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

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

The refactored BuildRenderTree method introduces new conditional logic where EnableErrorLogger false directly renders ChildContent without the CascadingValue wrapper. However, there are no tests in ErrorLoggerTest.cs that verify this specific behavior. Consider adding a test that verifies when EnableErrorLogger is false, the CascadingValue is not created and ChildContent is rendered directly.

Copilot uses AI. Check for mistakes.
Comment on lines +104 to +115
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

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

When EnableErrorLogger is false, the _errorBoundary field will not be initialized (remains null). While the current call site in BootstrapComponentBase checks EnableErrorLogger before calling HandlerExceptionAsync (line 136), the method itself is public and part of the IErrorLogger interface. Consider adding a null check or EnableErrorLogger guard within HandlerExceptionAsync to make it safer for direct calls and prevent potential NullReferenceException if the method is called when EnableErrorLogger is false.

Copilot uses AI. Check for mistakes.
}

private RenderFragment? RenderContent => EnableErrorLogger ? RenderError : ChildContent;

private RenderFragment RenderError => builder =>
{
builder.OpenComponent<BootstrapBlazorErrorBoundary>(0);
Expand All @@ -119,7 +124,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
builder.AddAttribute(4, nameof(BootstrapBlazorErrorBoundary.ErrorContent), ErrorContent);
builder.AddAttribute(5, nameof(BootstrapBlazorErrorBoundary.ChildContent), ChildContent);
builder.AddAttribute(6, nameof(BootstrapBlazorErrorBoundary.EnableILogger), EnableILogger);
builder.AddComponentReferenceCapture(5, obj => _errorBoundary = (BootstrapBlazorErrorBoundary)obj);
builder.AddComponentReferenceCapture(7, obj => _errorBoundary = (BootstrapBlazorErrorBoundary)obj);
builder.CloseComponent();
};

Expand Down
Loading