@@ -235,15 +235,29 @@ private StringWriter StringWriter
235235 }
236236
237237 /// <inheritdoc />
238- public override void Process ( TagHelperContext context , TagHelperOutput output )
238+ public override async Task ProcessAsync ( TagHelperContext context , TagHelperOutput output )
239239 {
240240 ArgumentNullException . ThrowIfNull ( context ) ;
241241 ArgumentNullException . ThrowIfNull ( output ) ;
242242
243243 if ( string . Equals ( Type , "importmap" , StringComparison . OrdinalIgnoreCase ) )
244244 {
245- // This is an importmap script, we'll write out the import map and
246- // stop processing.
245+ // Do not update the content if another tag helper targeting this element has already done so.
246+ if ( output . IsContentModified )
247+ {
248+ return ;
249+ }
250+
251+ // This is an importmap script, check if there's existing content first.
252+ var childContent = await output . GetChildContentAsync ( ) ;
253+ if ( ! childContent . IsEmptyOrWhiteSpace )
254+ {
255+ // User provided existing content; preserve it.
256+ output . Content . SetHtmlContent ( childContent ) ;
257+ return ;
258+ }
259+
260+ // No existing content, so we can apply import map logic.
247261 var importMap = ImportMap ?? ViewContext . HttpContext . GetEndpoint ( ) ? . Metadata . GetMetadata < ImportMapDefinition > ( ) ;
248262 if ( importMap == null )
249263 {
@@ -252,10 +266,10 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
252266 return ;
253267 }
254268
269+ output . Content . SetHtmlContent ( importMap . ToString ( ) ) ;
255270 output . TagName = "script" ;
256271 output . TagMode = TagMode . StartTagAndEndTag ;
257272 output . Attributes . SetAttribute ( "type" , "importmap" ) ;
258- output . Content . SetHtmlContent ( importMap . ToString ( ) ) ;
259273 return ;
260274 }
261275
0 commit comments