Skip to content

aspnetcore-browser-refresh.js injected into JSON content #61838

@bsrobinson

Description

@bsrobinson

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The <script src="/_framework/aspnetcore-browser-refresh.js"></script> is being inserted before the </body> tag in HTML content that is contained in JSON

This is breaking the rendering in the browser and preventing hot reload from working

Expected Behavior

The aspnetcore-browser-refresh.js script tag should be inserted before the root tag, not within quoted text

Steps To Reproduce

Here is my Layout.cshtml file; the page loaded via RenderBody is empty

<html>
    <body>
        @RenderBody()
    </body>
    <script>
        var data = [{"HtmlContent":{"en":"<html><body><div></div></body></html>"}}]
    </script>
</html>

The rendered html from the browser looks like this:

<html>
    <body>
        
    </body>
    <script>
        var data = [{"HtmlContent":{"en":"<html><body><div></div><script src="/_framework/aspnetcore-browser-refresh.js"></script></body></html>"}}]
    </script>
</html>

The error also occurs when the script tag is at the top of the page, but only seemed to happen when there was a large amount of JSON; I'm seeing this constantly on a page with the script tag at the top, with the JSON containing about 500k of data, including a couple of base64 images in the HTML.

Exceptions (if any)

Browser reports "SyntaxError: Unexpected EOF"

.NET Version

8.0.403

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Componentsfeature-hot-reloadThis issue is related to the Hot Reload feaature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions