Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9529163

Browse files
Define IErrorBoundary as an internal interface for clarity
1 parent415d8dd commit9529163

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

‎src/Components/Components/src/ErrorBoundaryBase.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Components
1111
/// <summary>
1212
/// A base class for error boundary components.
1313
/// </summary>
14-
publicabstractclassErrorBoundaryBase:IComponent
14+
publicabstractclassErrorBoundaryBase:IComponent,IErrorBoundary
1515
{
1616
// This deliberately doesn't inherit from ComponentBase because it's not intended to be
1717
// subclassable using a .razor file. ErrorBoundaryBase shouldn't be used as a base class
@@ -91,7 +91,7 @@ public Task SetParametersAsync(ParameterView parameters)
9191
/// <param name="exception">The current exception.</param>
9292
protectedabstractvoidRenderDefaultErrorContent(RenderTreeBuilderbuilder,Exceptionexception);
9393

94-
internalvoidHandleException(Exceptionexception)
94+
voidIErrorBoundary.HandleException(Exceptionexception)
9595
{
9696
if(_currentExceptionis notnull)
9797
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
usingSystem;
5+
6+
namespaceMicrosoft.AspNetCore.Components
7+
{
8+
// Purpose of this interface, instead of just using ErrorBoundaryBase directly:
9+
//
10+
// [1] It keeps clear what is fundamental to an error boundary from the Renderer's perspective.
11+
// Anything more specific than this is just a useful pattern inside ErrorBoundaryBase.
12+
// [2] It improves linkability. If an application isn't using error boundaries, then all of
13+
// ErrorBoundaryBase and its dependencies can be linked out, leaving only this interface.
14+
//
15+
// If we wanted, we could make this public, but it could lead to common antipatterns such as
16+
// routinely marking all components as error boundaries (e.g., in a common base class) in an
17+
// attempt to create "On Error Resume Next"-type behaviors.
18+
19+
internalinterfaceIErrorBoundary
20+
{
21+
voidHandleException(Exceptionerror);
22+
}
23+
}

‎src/Components/Components/src/RenderTree/Renderer.cs‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,13 @@ private bool TrySendExceptionToErrorBoundary(IComponent? errorSource, Exception
394394
// Find the closest error boundary, if any
395395
while(componentStateis notnull)
396396
{
397-
if(componentState.ComponentisErrorBoundaryBaseerrorBoundary)
397+
if(componentState.ComponentisIErrorBoundaryerrorBoundary)
398398
{
399-
// Force the IErrorBoundary component to clear its output, regardless of any logic inside
400-
// that component. This ensures that all descendants are cleaned up. We don't strictly have
401-
// to do this, since the only errors we handle this way are actually recoverable, so technically
402-
// it would be OK if the old output was left in place and continued operating. However that
403-
// would be a whole new way of keeping components running after failure which we don't want
404-
// to introduce and guarantee to support forever.
399+
// Even though ErrorBoundaryBase always removes its ChildContent from the tree when
400+
// switching into an error state, the Renderer doesn't rely on that. To guarantee that
401+
// the failed subtree is disposed, forcibly remove it here. If the failed components did
402+
// continue to run, it wouldn't harm framework state, but it would be a whole new kind of
403+
// edge case to support forever.
405404
AddToRenderQueue(componentState.ComponentId, builder=>{});
406405

407406
try

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp