Skip to content

The ScriptTagHelper doesn't render the type attribute of the <script> tag when the target framework is .NET 9 #57664

Closed
@jsakamoto

Description

@jsakamoto

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The ScriptTagHelper doesn't render the type attribute of the <script> tag when the target framework is the .NET 9. This problem will happen in both MVC Views and Razor Pages.

Expected Behavior

The ScriptTagHelper should render the type attribute of the <script> tag, as well as the .NET 8 is doing.

Steps To Reproduce

Step 1. Download and extract the zip file I attached below.

That zip file includes an ASPNET Core Razor Pages project that owns a default Razor Page (Index.cshtml) that includes the <script> tag with the type="module" attribute.

...
<body>
    <h1>Index</h1>
    <script type="module" src="~/index.js" asp-append-version="true"></script>
</body>
</html>

Step 2. Run that project with the following command in a terminal console.

dotnet run -f net9.0 --urls http://localhost:5000/

Step 3. Fetch the default document of that app with the following command in another terminal console.

curl http://localhost:5000/

Expected: I expected that I could see the output like the one below.

...
<body>
    <h1>Index</h1>
    <script type="module" src="/index.eeak79n6tu.js"></script>
</body>
</html>

Actual: I could not see the type attribute in the document the app rendered.

...
<body>
    <h1>Index</h1>
    <script src="/index.eeak79n6tu.js"></script>
</body>
</html>

Appendix

  • This problem won't happen when the target framework is .NET 8, not .NET 9. (You can verify that behavior with the command dotnet run -f net8.0 --urls http://localhost:5000/)

  • This problem also happens on MVC Views even if the target framework is .NET 9. (See also: 📦MvcApp1.zip)

Exceptions (if any)

There will be an error message in the web browser's developer console, like this:

Cannot use import statement outside a module.

.NET Version

9.0.100-preview.7.24407.12

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: DuplicateResolved as a duplicate of another issueStatus: Resolvedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions