Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Mvc/Mvc.TagHelpers/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
*REMOVED*~override Microsoft.AspNetCore.Mvc.TagHelpers.ScriptTagHelper.Process(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) -> void
~override Microsoft.AspNetCore.Mvc.TagHelpers.ScriptTagHelper.ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output) -> System.Threading.Tasks.Task
22 changes: 18 additions & 4 deletions src/Mvc/Mvc.TagHelpers/src/ScriptTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,29 @@ private StringWriter StringWriter
}

/// <inheritdoc />
public override void Process(TagHelperContext context, TagHelperOutput output)
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(output);

if (string.Equals(Type, "importmap", StringComparison.OrdinalIgnoreCase))
{
// This is an importmap script, we'll write out the import map and
// stop processing.
// Do not update the content if another tag helper targeting this element has already done so.
if (output.IsContentModified)
{
return;
}

// This is an importmap script, check if there's existing content first.
var childContent = await output.GetChildContentAsync();
if (!childContent.IsEmptyOrWhiteSpace)
{
// User provided existing content; preserve it.
output.Content.SetHtmlContent(childContent);
return;
}

// No existing content, so we can apply import map logic.
var importMap = ImportMap ?? ViewContext.HttpContext.GetEndpoint()?.Metadata.GetMetadata<ImportMapDefinition>();
if (importMap == null)
{
Expand All @@ -252,10 +266,10 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
return;
}

output.Content.SetHtmlContent(importMap.ToString());
output.TagName = "script";
output.TagMode = TagMode.StartTagAndEndTag;
output.Attributes.SetAttribute("type", "importmap");
output.Content.SetHtmlContent(importMap.ToString());
return;
}

Expand Down
Loading
Loading