@@ -242,27 +242,31 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
242242
243243 if ( string . Equals ( Type , "importmap" , StringComparison . OrdinalIgnoreCase ) )
244244 {
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+
245251 // This is an importmap script, check if there's existing content first.
246252 var childContent = await output . GetChildContentAsync ( ) ;
247253 if ( ! childContent . IsEmptyOrWhiteSpace )
248254 {
249255 // User provided existing content; preserve it.
250256 output . Content . SetHtmlContent ( childContent ) ;
257+ return ;
251258 }
252- else
253- {
254- // No existing content, so we can apply import map logic.
255- var importMap = ImportMap ?? ViewContext . HttpContext . GetEndpoint ( ) ? . Metadata . GetMetadata < ImportMapDefinition > ( ) ;
256- if ( importMap == null )
257- {
258- // No importmap found, nothing to do.
259- output . SuppressOutput ( ) ;
260- return ;
261- }
262259
263- output . Content . SetHtmlContent ( importMap . ToString ( ) ) ;
260+ // No existing content, so we can apply import map logic.
261+ var importMap = ImportMap ?? ViewContext . HttpContext . GetEndpoint ( ) ? . Metadata . GetMetadata < ImportMapDefinition > ( ) ;
262+ if ( importMap == null )
263+ {
264+ // No importmap found, nothing to do.
265+ output . SuppressOutput ( ) ;
266+ return ;
264267 }
265268
269+ output . Content . SetHtmlContent ( importMap . ToString ( ) ) ;
266270 output . TagName = "script" ;
267271 output . TagMode = TagMode . StartTagAndEndTag ;
268272 output . Attributes . SetAttribute ( "type" , "importmap" ) ;
0 commit comments