@@ -2683,7 +2683,7 @@ public void ExceptionsReturnedUsingTaskFromExceptionCanBeHandled()
2683
2683
}
2684
2684
2685
2685
[ Fact ]
2686
- public async Task ExceptionsThrownAsynchronouslyCanBeHandled ( )
2686
+ public async Task ExceptionsThrownAsynchronouslyDuringFirstRenderCanBeHandled ( )
2687
2687
{
2688
2688
// Arrange
2689
2689
var renderer = new TestRenderer { ShouldHandleExceptions = true } ;
@@ -2722,6 +2722,36 @@ public async Task ExceptionsThrownAsynchronouslyCanBeHandled()
2722
2722
Assert . Same ( exception , Assert . Single ( renderer . HandledExceptions ) . GetBaseException ( ) ) ;
2723
2723
}
2724
2724
2725
+ [ Fact ]
2726
+ public async Task ExceptionsThrownAsynchronouslyAfterFirstRenderCanBeHandled ( )
2727
+ {
2728
+ // This differs from the "during first render" case, because some aspects of the rendering
2729
+ // code paths are special cased for the first render because of prerendering.
2730
+
2731
+ // Arrange
2732
+ var renderer = new TestRenderer { ShouldHandleExceptions = true } ;
2733
+ var taskToAwait = Task . CompletedTask ;
2734
+ var component = new TestComponent ( builder =>
2735
+ {
2736
+ builder . OpenComponent < ComponentThatAwaitsTask > ( 0 ) ;
2737
+ builder . AddAttribute ( 1 , nameof ( ComponentThatAwaitsTask . TaskToAwait ) , taskToAwait ) ;
2738
+ builder . CloseComponent ( ) ;
2739
+ } ) ;
2740
+ var componentId = renderer . AssignRootComponentId ( component ) ;
2741
+ await renderer . RenderRootComponentAsync ( componentId ) ; // Not throwing on first render
2742
+
2743
+ var asyncExceptionTcs = new TaskCompletionSource < object > ( ) ;
2744
+ taskToAwait = asyncExceptionTcs . Task ;
2745
+ await renderer . Invoke ( component . TriggerRender ) ;
2746
+
2747
+ // Act
2748
+ var exception = new InvalidOperationException ( ) ;
2749
+ asyncExceptionTcs . SetException ( exception ) ;
2750
+
2751
+ // Assert
2752
+ Assert . Same ( exception , Assert . Single ( renderer . HandledExceptions ) . GetBaseException ( ) ) ;
2753
+ }
2754
+
2725
2755
[ Fact ]
2726
2756
public async Task ExceptionsThrownAsynchronouslyFromMultipleComponentsCanBeHandled ( )
2727
2757
{
@@ -3696,5 +3726,15 @@ public enum EventType
3696
3726
OnAfterRenderAsync ,
3697
3727
}
3698
3728
}
3729
+
3730
+ private class ComponentThatAwaitsTask : ComponentBase
3731
+ {
3732
+ [ Parameter ] public Task TaskToAwait { get ; set ; }
3733
+
3734
+ protected override async Task OnParametersSetAsync ( )
3735
+ {
3736
+ await TaskToAwait ;
3737
+ }
3738
+ }
3699
3739
}
3700
3740
}
0 commit comments