aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Blazor.webassembly.js - Unhandled exception rendering component: Cannot read properties of null (reading 'removeChild')

Open alinapereira opened this issue 1 year ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

The function below should have a validation for when the parentNode is null before attempting to remove its child node:

function $(e, t) {
        const n = U(e).splice(t, 1)[0];
        if (n instanceof Comment) {
            const e = U(n);
            if (e)
                for (; e.length > 0; )
                    $(n, 0)
        }
        const r = n;
        r.parentNode.removeChild(r)
        }

In the print below you can check that the parent instance is null, leading to this type of exception: blazor.webassembly.js?v=7.0:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Cannot read properties of null (reading 'removeChild') TypeError: Cannot read properties of null (reading 'removeChild') at $ (https://.../_framework/blazor.webassembly.js?v=7.0:1:17340) Screenshot_1

Expected Behavior

By adding the validation when the parentNode is not null the child node will still be removed, when the parent element is null then no error will be shown in the console.

Steps To Reproduce

This error is showing on the browser console since we updated the .NET version from 6 to 7.

Exceptions (if any)

No response

.NET Version

7 and above

Anything else?

No response

alinapereira avatar May 03 '24 13:05 alinapereira

Running into this as well but difficult to reproduce.

rogihee avatar May 21 '24 19:05 rogihee