Skip to content

Resources not get disposed of in SortableList.razor #14

@Owenll66

Description

@Owenll66

The file is missing implementing IAsyncDisposable/IDisposable. The blazor framework won't recognize the Dispose() method and it will never get executed.

I think it needs

@implements IAsyncDisposable

The IJSObjectReference module needs to get disposed of too, and we need a private field for it.

private IJSObjectReference? module;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    if (firstRender)
    {
        selfReference = DotNetObjectReference.Create(this);
        // Should module get disposed of as well?
        module = await JS.InvokeAsync<IJSObjectReference>("import", "./Shared/SortableList.razor.js");
        await module.InvokeAsync<string>("init", Id, Group, Pull, Put, Sort, Handle, Filter, selfReference, ForceFallback);
    }
}

And finally

public async ValueTask DisposeAsync()
{
    selfReference?.Dispose();
    await module!.DisposeAsync();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions