Skip to content

QuickGrid has a race condition with disposal during init #47173

@SteveSandersonMS

Description

@SteveSandersonMS

Discovered by @kg (thanks!)

QuickGrid's OnAfterRenderAsync logic looks like the following approximation:

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    if (firstRender)
    {
        // First load the module, then call its "init" export
        var jsModule = await JS.InvokeAsync("import", ...);
        await jsModule.InvokeAsync("init", ...);
    }
}

However that logic contains a bug. If the component is disposed while the import async call is in progress, then the continuation will still try to call init, but by now the corresponding DOM elements have been removed so it will result in an error.

The fix is to check if we've already been disposed immediately before calling init, and skip it if so. That would make it not a race condition because the sync context is single-threaded and hence the scheduled init call would necessarily be delivered before any call that would remove the grid from the DOM.

Repro

Make a grid that takes multiple seconds to render (e.g., put Thread.Sleep inside a template column rendering body). While that is in flight, click on a navigation link to go elsewhere in the site. Because the init call still runs, you'll get a console error like:

TypeError: Cannot read properties of null (reading 'tHead')

Metadata

Metadata

Assignees

Labels

Pillar: Technical DebtPriority:2Work that is important, but not critical for the releasearea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-blazor-quickgrid

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions