Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Jan 9, 2026

Link issues

fixes #7482

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Gate the ErrorLogger cascading component and error boundary rendering on the EnableErrorLogger flag and tighten error logging conditions.

Bug Fixes:

  • Avoid wrapping child content in the error logging infrastructure when error logging is disabled by the EnableErrorLogger flag.
  • Prevent logging when the ILogger is not enabled for Error level to reduce unnecessary log entries.

Enhancements:

  • Simplify the ErrorLogger render logic by inlining the conditional rendering instead of using an intermediate RenderFragment property.

Copilot AI review requested due to automatic review settings January 9, 2026 13:42
@bb-auto bb-auto bot added the enhancement New feature or request label Jan 9, 2026
@bb-auto bb-auto bot added this to the v10.2.0 milestone Jan 9, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 9, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR updates the ErrorLogger component so that it conditionally provides the error-logging cascading context only when error logging is enabled, and tightens logging behavior in the BootstrapBlazorErrorBoundary to only log when ILogger is enabled for error level.

Sequence diagram for conditional error logging and rendering

sequenceDiagram
    actor User
    participant ErrorLogger
    participant CascadingValue_IErrorLogger_ as CascadingValue_IErrorLogger
    participant ChildComponent
    participant BootstrapBlazorErrorBoundary as ErrorBoundary
    participant ILogger as Logger

    User->>ErrorLogger: Render
    activate ErrorLogger
    alt EnableErrorLogger is true
        ErrorLogger->>CascadingValue_IErrorLogger: Provide IErrorLogger context
        CascadingValue_IErrorLogger->>ErrorBoundary: RenderError (wrap ChildContent)
        activate ErrorBoundary
        User->>ChildComponent: Interact (may cause exception)
        ChildComponent-->>ErrorBoundary: Exception thrown
        ErrorBoundary->>ErrorBoundary: OnErrorAsync(exception)
        alt EnableILogger and Logger.IsEnabled(Error)
            ErrorBoundary->>Logger: LogError(exception, uri)
        else logging disabled
            ErrorBoundary-->>Logger: No call
        end
        deactivate ErrorBoundary
    else EnableErrorLogger is false
        ErrorLogger->>ChildComponent: Render ChildContent directly
        User->>ChildComponent: Interact (exceptions not logged here)
    end
    deactivate ErrorLogger
Loading

Class diagram for updated ErrorLogger and BootstrapBlazorErrorBoundary behavior

classDiagram
    class IErrorLogger

    class ErrorLogger {
        bool EnableErrorLogger
        RenderFragment ChildContent
        RenderFragment ErrorContent
        bool EnableILogger
        BootstrapBlazorErrorBoundary _errorBoundary
        +BuildRenderTree(RenderTreeBuilder builder) void
        -RenderError RenderFragment
    }

    class CascadingValue_IErrorLogger_ {
        IErrorLogger Value
        bool IsFixed
        RenderFragment ChildContent
    }

    class BootstrapBlazorErrorBoundary {
        bool EnableILogger
        ILogger Logger
        NavigationManager NavigationManager
        RenderFragment ErrorContent
        RenderFragment ChildContent
        +OnErrorAsync(Exception exception) Task
    }

    ErrorLogger ..|> IErrorLogger
    ErrorLogger --> CascadingValue_IErrorLogger_ : wraps
    ErrorLogger --> BootstrapBlazorErrorBoundary : creates
    BootstrapBlazorErrorBoundary --> ILogger : uses
    BootstrapBlazorErrorBoundary --> NavigationManager : uses
Loading

File-Level Changes

Change Details Files
Gate the ErrorLogger cascading context and error boundary rendering on the EnableErrorLogger flag instead of always wrapping children.
  • Wrap the CascadingValue and error boundary rendering in a conditional block that only executes when EnableErrorLogger is true.
  • When EnableErrorLogger is false, render ChildContent directly without CascadingValue or error boundary wrapping.
  • Remove the RenderContent helper property and use RenderError directly as the ChildContent of the CascadingValue when enabled.
  • Adjust the component reference capture sequence number to remain consistent with the updated render tree.
src/BootstrapBlazor/Components/ErrorLogger/ErrorLogger.cs
Ensure error logging from BootstrapBlazorErrorBoundary only occurs when ILogger is configured to log errors.
  • Add a LogLevel.Error enablement check to the existing EnableILogger guard in OnErrorAsync before calling Logger.LogError.
src/BootstrapBlazor/Components/ErrorLogger/BootstrapBlazorErrorBoundary.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7482 Make the ErrorLogger component actually respect the EnableErrorLogger parameter when rendering, so that error logging/wrapping is only applied when EnableErrorLogger is true and the child content is rendered directly when it is false.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArgoZhang ArgoZhang merged commit bbaa32e into main Jan 9, 2026
6 of 8 checks passed
@ArgoZhang ArgoZhang deleted the feat-error branch January 9, 2026 13:42
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.98%. Comparing base (5da30ea) to head (a65c196).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...onents/ErrorLogger/BootstrapBlazorErrorBoundary.cs 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main    #7483      +/-   ##
===========================================
- Coverage   100.00%   99.98%   -0.02%     
===========================================
  Files          749      749              
  Lines        32936    32941       +5     
  Branches      4576     4576              
===========================================
+ Hits         32936    32937       +1     
- Misses           0        3       +3     
- Partials         0        1       +1     
Flag Coverage Δ
BB 99.98% <92.30%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the ErrorLogger component to properly respect the EnableErrorLogger parameter by conditionally rendering the error handling infrastructure only when enabled, and adds a performance optimization to check log level before logging.

  • Refactored BuildRenderTree to conditionally render error handling based on EnableErrorLogger
  • Fixed component reference capture index from 5 to 7 (correcting a bug)
  • Added Logger.IsEnabled(LogLevel.Error) check before logging for performance optimization

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/BootstrapBlazor/Components/ErrorLogger/ErrorLogger.cs Refactored BuildRenderTree to check EnableErrorLogger and conditionally wrap content in CascadingValue with error boundary; removed RenderContent property; fixed component reference capture index
src/BootstrapBlazor/Components/ErrorLogger/BootstrapBlazorErrorBoundary.cs Added Logger.IsEnabled check before logging to avoid unnecessary logging overhead

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +104 to +115
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);
}
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
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);
}
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(ErrorLogger): check EnableErrorLogger parameter

2 participants