@@ -39,15 +39,18 @@ public async Task CanCorrectlyDisposeAsync()
3939 // Complete the JS module loading
4040 moduleLoadCompletion . SetResult ( ) ;
4141
42- // Assert that init was not called after disposal
42+ // Wait until after OnAfterRenderAsync has completed to test the disposal of the jsModule
43+ var notFailingGrid = testComponent . NotFailingGrid ;
44+ await notFailingGrid . OnAfterRenderCompleted ;
45+
46+ // Assert that init was not called after disposal and JsModule was disposed of
4347 Assert . False ( testJsRuntime . InitWasCalledAfterDisposal ,
4448 "Init should not be called on a disposed component." ) ;
45- await Task . Yield ( ) ;
4649 Assert . True ( testJsRuntime . JsModuleDisposed ) ;
4750 }
4851
4952 [ Fact ]
50- public async Task FailingQuickGrid_CallsInitAfterDisposal_DemonstratesRaceCondition ( )
53+ public async Task FailingQuickGridCallsInitAfterDisposal ( )
5154 {
5255 var moduleLoadCompletion = new TaskCompletionSource ( ) ;
5356 var moduleImportStarted = new TaskCompletionSource ( ) ;
@@ -69,21 +72,17 @@ public async Task FailingQuickGrid_CallsInitAfterDisposal_DemonstratesRaceCondit
6972 testJsRuntime . MarkDisposed ( ) ;
7073 await renderer . DisposeAsync ( ) ;
7174
72- // Verify our FailingQuickGrid's DisposeAsync was called and _disposeBool should still be false
73- var failingGrid = testComponent . FailingQuickGrid ;
74- Assert . NotNull ( failingGrid ) ;
75- Assert . True ( failingGrid . DisposeAsyncWasCalled , "FailingQuickGrid.DisposeAsync should have been called" ) ;
76- Assert . True ( failingGrid . IsWasDisposedFalse ( ) , "_wasDisposed should still be false since we didn't call base.DisposeAsync()" ) ;
77-
7875 // Complete the JS module loading - this allows the FailingQuickGrid's OnAfterRenderAsync to continue
7976 // and demonstrate the race condition by calling init after disposal
8077 moduleLoadCompletion . SetResult ( ) ;
8178
8279 // Wait for OnAfterRenderAsync to complete - deterministic timing instead of arbitrary delay
80+ var failingGrid = testComponent . FailingQuickGrid ;
8381 await failingGrid . OnAfterRenderCompleted ;
8482
85- // Assert that init WAS called after disposal (demonstrating the race condition bug)
83+ // Assert that init WAS called after disposal
8684 // The FailingQuickGrid's OnAfterRenderAsync should have called init despite being disposed
85+ // The FailingQuickGrid should not have disposed of JsModule
8786 Assert . True ( testJsRuntime . InitWasCalledAfterDisposal ,
8887 $ "FailingQuickGrid should call init after disposal, demonstrating the race condition bug. " +
8988 $ "InitWasCalledAfterDisposal: { testJsRuntime . InitWasCalledAfterDisposal } , " +
@@ -122,16 +121,14 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
122121 b . AddAttribute ( 1 , "Property" , ( System . Linq . Expressions . Expression < Func < Person , int > > ) ( p => p . Id ) ) ;
123122 b . CloseComponent ( ) ;
124123 } ) ) ;
125- if ( typeof ( TGrid ) != typeof ( QuickGrid < Person > ) )
126- {
127- builder . AddComponentReferenceCapture ( 3 , component => _grid = ( TGrid ) component ) ;
128- }
124+ builder . AddComponentReferenceCapture ( 3 , component => _grid = ( TGrid ) component ) ;
129125 builder . CloseComponent ( ) ;
130126 }
131127}
132128
133- internal class SimpleTestComponent : BaseTestComponent < QuickGrid < Person > >
129+ internal class SimpleTestComponent : BaseTestComponent < NotFailingGrid < Person > >
134130{
131+ public NotFailingGrid < Person > NotFailingGrid => Grid ;
135132}
136133
137134internal class FailingGridTestComponent : BaseTestComponent < FailingQuickGrid < Person > >
0 commit comments