Repository: dotnet/aspnetcore
File: src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/test/FailingQuickGrid.cs (C#)

Code before:
    public Task OnAfterRenderCompleted => _onAfterRenderCompleted.Task;

    /// <summary>
    /// Intentionally does NOT call base.DisposeAsync() to prevent _disposeBool from being set.
    /// This simulates the behavior before the fix was implemented.
    /// </summary>
    public new async ValueTask DisposeAsync()
    {
        DisposeAsyncWasCalled = true;
        await Task.CompletedTask;
    }

    /// <summary>
    /// Explicit interface implementation to ensure our disposal method is called.
    /// </summary>
    async ValueTask IAsyncDisposable.DisposeAsync()
    {
        await DisposeAsync();
    }

    /// <summary>
    /// Check if _disposeBool is false, proving we didn't call base.DisposeAsync().
    /// This is used by tests to verify that our simulation is working correctly.
    /// </summary>
    public bool IsWasDisposedFalse()
    {
        var field = typeof(QuickGrid<TGridItem>).GetField("_wasDisposed", BindingFlags.NonPublic | BindingFlags.Instance);
        return field?.GetValue(this) is false;
    }

    /// <summary>
    /// Override OnAfterRenderAsync to simulate the race condition by NOT checking _disposeBool.
    /// This exactly replicates the code path that existed before the race condition fix.
    /// </summary>
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        try
        {
            if (firstRender)
            {
                if (JS != null)
                {
                    // Import the JS module (this will trigger our TestJsRuntime's import logic)
                    var jsModule = await JS.InvokeAsync<IJSObjectReference>("import",
                        "./_content/Microsoft.AspNetCore.Components.QuickGrid/QuickGrid.razor.js");

                    await jsModule.InvokeAsync<IJSObjectReference>("init", new object());

                    // Signal completion only after the init call has completed, and only once
                    if (!_completionSignaled)
                    {

Review comment (bug):
Using reflection to access private fields creates tight coupling and fragile tests. The field name `_wasDisposed` doesn't match the actual field name `_disposeBool` used in the main code, which will cause this method to always return false incorrectly.
```suggestion
        var field = typeof(QuickGrid<TGridItem>).GetField("_disposeBool", BindingFlags.NonPublic | BindingFlags.Instance);
```

Code after:

    /// <summary>
    /// Intentionally does NOT call base.DisposeAsync() to prevent _disposeBool from being set.
    /// This simulates the behavior before the fix was implemented.
    /// </summary>
    public new async ValueTask DisposeAsync()
    {
        DisposeAsyncWasCalled = true;
        await Task.CompletedTask;
    }

    /// <summary>
    /// Explicit interface implementation to ensure our disposal method is called.
    /// </summary>
    async ValueTask IAsyncDisposable.DisposeAsync()
    {
        await DisposeAsync();
    }

    /// <summary>
    /// Check if _disposeBool is false, proving we didn't call base.DisposeAsync().
    /// This is used by tests to verify that our simulation is working correctly.
    /// </summary>
    public bool IsWasDisposedFalse()
    {
        var field = typeof(QuickGrid<TGridItem>).GetField("_wasDisposed", BindingFlags.NonPublic | BindingFlags.Instance);
        return field?.GetValue(this) is false;
    }

    /// <summary>
    /// Override OnAfterRenderAsync to simulate the race condition by NOT checking _disposeBool.
    /// This exactly replicates the code path that existed before the race condition fix.
    /// </summary>
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        try
        {
            if (firstRender)
            {
                if (JS != null)
                {
                    // Import the JS module (this will trigger our TestJsRuntime's import logic)
                    var jsModule = await JS.InvokeAsync<IJSObjectReference>("import",
                        "./_content/Microsoft.AspNetCore.Components.QuickGrid/QuickGrid.razor.js");
                    await jsModule.InvokeAsync<IJSObjectReference>("init", new object());
                }
            }
        }
        finally
        {
            if (firstRender)