aspnetcore: blazor headcontent throws exception

This issue has been moved from a ticket on Developer Community.


[severity:Other] Head content throws exceptions when using global interactive server mode.

Repro:

  1. Create a new blazor server app project.

  2. For “Interactive Render Mode”, select “Server”.

  3. For “Interactivity Location”, select “Global”.

  4. Add a HeadContent component to the “Home.razor” page. Inside that component, and any valid HTML (doesn’t have to be a blazor component).

  5. Run the application.

  6. From the “Home Page”, navigate to the “Counter” page.

  7. Click on the browsers “Back” button (using Edge in this case) or click the sidebar nav link for Counter that also has a meta tag

  8. Default blazor error message appears.

Here is the error message from the Output or Immediate Window

Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: TypeError: Cannot read properties of null (reading 'insertBefore')

System.InvalidOperationException: TypeError: Cannot read properties of null (reading 'insertBefore')
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'XwKDhTBqDdbOIORvnq38ZTsq1zlmyisXYpb55dTgcUg'.

System.AggregateException: One or more errors occurred. (TypeError: Cannot read properties of null (reading 'insertBefore'))
 ---> System.InvalidOperationException: TypeError: Cannot read properties of null (reading 'insertBefore')
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
   --- End of inner exception stack trace ---

Wait for the Microsoft Developer Community Bot to tell us that this is closed, not enough info or this is expected with no further explanation.


Original Comments

Feedback Bot on 3/28/2024, 00:45 AM:

(private comment, text removed)


Original Solutions

(no solutions)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 21 (9 by maintainers)

Commits related to this issue

Most upvoted comments

If I swap the position of the isolated css file

    <link href="BlazorApp4.styles.css" rel="stylesheet" />
    <HeadOutlet @rendermode="new InteractiveServerRenderMode(false)" />

to

    <HeadOutlet @rendermode="new InteractiveServerRenderMode(false)" />
    <link href="BlazorApp4.styles.css" rel="stylesheet" />

it works with no issues.

Running into the same issue in .net 8.0.4.

Having a HeadOutlet with the rendermode set in App.razor and setting the PageTitle in a page results in

System.InvalidOperationException: TypeError: Cannot read properties of null (reading 'insertBefore')
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)

Removing the rendermode eliminates the error, but the page title is no longer dynamically updated by the page, of course.

Workaround: Setting a default PageTitle AFTER the HeadOutlet fixes the problem and updates the title as expected:

<HeadOutlet @rendermode="InteractiveServer"></HeadOutlet>
<PageTitle>Default Page Title</PageTitle>

Thanks @hakenr for sharing the workaround and figuring out the source of the issue!

@SteveSandersonMS @javiercn Is it worth investigating to see if there’s anything we can do to make Blazor apps more resilient to browser extensions like LastPass?

LastPass 4.130.0 is out that resolves the error

I can confirm that with 4.130.0 the issue no longer reproduces.

LastPass 4.130.0 is out that resolves the error

Woohoo, the issue is most likely caused by the updated LastPass browser extension. When I disable LastPass, the issue disappears. When I re-enable LastPass, the issue immediately returns.

I wish Blazor were less “vulnerable” to these situations, but I have to admit this is most likely due to external DOM manipulation without any chance for Blazor to handle it correctly.

Anyway, adding any element after the HeadOutlet prevents this issue from occurring.

Seeing this as well. Same reproducing steps.

Definitely open to ideas on that but in general random DOM mutations can cause problems, not only to Blazor but to other SPA tech also.