dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
34.51k stars 9.75k forks source link

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

Closed alinapereira closed 2 days ago

alinapereira commented 2 weeks ago

Is there an existing issue for this?

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

dotnet-policy-service[bot] commented 1 week ago

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimal repro project that illustrates the problem without unnecessary code. Please share with us in a public GitHub repo because we cannot open ZIP attachments, and don't include any confidential content.

dotnet-policy-service[bot] commented 6 days ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.