Megabit / Blazorise

Blazorise is a component library built on top of Blazor with support for CSS frameworks like Bootstrap, Tailwind, Bulma, AntDesign, and Material.
https://blazorise.com/
Other
3.31k stars 533 forks source link

[Bug]: The ReadData method is executed once when the datagrid component throws an exception #5566

Open He-Wu opened 5 months ago

He-Wu commented 5 months ago

Blazorise Version

1.2.3

What Blazorise provider are you running on?

Bootstrap5

Link to minimal reproduction or a simple code snippet

public List<Demo1Dto> GridData { get; set; } = new();
private async Task TestPageError(MouseEventArgs arg)
        {
            throw new Exception("throw error");

        }
private async Task ReadData(DataGridReadDataEventArgs<Demo1Dto> arg)
        {
            for (int i = 0; i < 10; i++)
            {
                await Task.Delay(1000);
                GridData.Add(new Demo1Dto() { name = "Test" + i});
            }
        }
<Button Size="Size.ExtraLarge" Clicked="TestPageError" Color="Color.Danger">TestPageError</Button>
<DataGrid
    TItem="Demo1Dto"
    Data="GridData"
    ReadData="ReadData"
>
    <DataGridColumns>
        <DataGridColumn Field="@nameof(Demo1Dto.name)" Caption="@nameof(Demo1Dto.name)" ></DataGridColumn>
    </DataGridColumns>
</DataGrid>

Steps to reproduce

When using the ReadData method of the datagrid component to simulate reading data from the database, if any error is triggered on the page (for example, clicking the button to throw an exception in the example code), the ReadData method is executed once. This results in an additional database query. I merely threw an exception, and it inexplicably executed a query, which seems very strange. I think it shouldn't execute a query when an exception is triggered.

What is expected?

When an exception is thrown, the ReadData method should not be executed.

What is actually happening?

1

What browsers do you see the problem on?

Chrome

Any additional comments?

No response

David-Moreira commented 4 months ago

That seems very very unlikely, an unhandled exception means that Blazor is being put into an invalid error state. Blazor Server will disconnect the circuiit, and likewise BlazorWebAssembly, both will be in an invalid state, where the app needs to recover, tipically by refreshing the page/ reloading the app.

So you might have some custom global error handling logic somewhere that wakes the app back up somehow, and your component is just straight up being reloaded, and that's why ReadData gets called again.

So the code you have provided does not allow to reproduce this issue, as a standard blazor app will be in an invalid state since an exception was thrown and not handled.

github-actions[bot] commented 4 months ago

Hello @He-Wu, thank you for your submission. The issue was labeled "Status: Repro Missing", as you have not provided a way to reproduce the issue quickly. Most problems already solve themselves when isolated, but we would like you to provide us with a reproducible code to make it easier to investigate a possible bug.