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
35.54k stars 10.05k forks source link

Razor regression in ASP .NET Core 9.0 #58973

Open AlexBAV opened 1 week ago

AlexBAV commented 1 week ago

Is there an existing issue for this?

Describe the bug

The following razor snippet renders to nothing (is completely ignored??) in ASP.NET Core 9.0. Used to work correctly in previous version:


<script type="importmap">
     {
         "imports": {
         }
    }
</script>

Looks like a bug in server-side script tag helper.

Expected Behavior

Should render "as is", without modifications

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

9.0.100

Anything else?

No response

ahazelwood commented 1 day ago

I would like to upgrade to 9.0, however this is hitting me on a asp.net core mvc project upgrading from net8.0. Any suggestions for how to get it to render correctly would be greatly appreciated. I concur that it should not override anything but render it as written.

AlexBAV commented 1 day ago

I currently use the following workaround for tag helpers that definitely should not be processed on a server side:

<!script type="importmap">...</!script>

<!tag> syntax is an official way to turn off tag helper processing.

However, I'm still sure that tag helper should not remove a tag if it cannot process it on a server side.

ahazelwood commented 1 day ago

Thanks Alexanderm, that’s a nice addition to know. I hadn’t come across that before. However, this should be fixed as it is an unexpected condition. At the very least, the documentation for importmap should indicate this as a temporary workaround until they are able to fix it.

Thanks for the pointer.

From: Alexander Bessonov @.> Sent: Thursday, November 21, 2024 4:20 AM To: dotnet/aspnetcore @.> Cc: Andre Hazelwood @.>; Comment @.> Subject: Re: [dotnet/aspnetcore] Razor regression in ASP .NET Core 9.0 (Issue #58973)

I currently use the following workaround for tag helpers that definitely should not be processed on a server side:

<!script type="importmap">...</!script>

<!tag> syntax is an official way to turn off tag helper processing.

However, I'm still sure that tag helper should not remove a tag if it cannot process it on a server side.

— Reply to this email directly, view it on GitHubhttps://github.com/dotnet/aspnetcore/issues/58973#issuecomment-2490478089, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AACS73GFMU2IM5ND3H5IIV32BWQTLAVCNFSM6AAAAABR2WEKWGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOJQGQ3TQMBYHE. You are receiving this because you commented.Message ID: @.**@.>>

AlexBAV commented 1 day ago

BTW, I suggest using this workaround for all "non-default" usages of script tag. It looks like they correctly recognize <script type="text/javascript">, <script type="module"> and <script>. All other usages should be guarded.

We, for example also had to implement a workaround for <script type="application/ld+json"> as it was also removed after upgrade to ASP.NET Core 9.0

StevePy commented 14 hours ago

This one caught me as well, a bit sweaty when my importmap (part of _Layout.cshtml) wasn't rendered, considering the relatively good feeling I had combining razor views with ES6 modules. Fortunately the work-around with the <!script type="importmap"> works a treat, but I can't see how that should be an expected breaking change since it's kind of a necessity for module scripts which are recognized. Fortunately a small work-around and pretty much everything else with the switch to .Net 9 has been relatively painless.