[release/10.0] Fix ScriptTagHelper regression by checking for existing content before processing importmaps #63631
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Script tag helper ask mode PR content
Backport of #63155 to release/10.0
/cc @MackinnonBuck @copilot
Fix ScriptTagHelper regression by checking for existing content before processing importmaps
Preserves developer-provided content in the
<script>
tag helper when itstype
is"importmap"
.Description
In .NET 9, we updated the
<script>
tag helper to automatically include an import map for fingerprinted JavaScript assets when itstype
attribute was set to"importmap"
.However, if the app had been specifying import map content explicitly, then that content would get overridden by the updated tag helper logic.
This fix changes
ScriptTagHelper
to preserve the any developer-specified import map content.Fixes #58973
Customer Impact
This bug impacts customers upgrading to .NET 9 or 10 from .NET 8. The linked issue has notable community engagement which indicates that many customers are affected by this break.
There is a workaround, which is to use the following syntax to bypass the tag helper:
<!script type="importmap">...</!script>
Regression?
Regressed in .NET 9
Risk
The fix is straightforward and has been validated via both automated and manual testing.
Verification
Packaging changes reviewed?