-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
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')