@@ -235,15 +235,29 @@ private StringWriter StringWriter
235
235
}
236
236
237
237
/// <inheritdoc />
238
- public override void Process ( TagHelperContext context , TagHelperOutput output )
238
+ public override async Task ProcessAsync ( TagHelperContext context , TagHelperOutput output )
239
239
{
240
240
ArgumentNullException . ThrowIfNull ( context ) ;
241
241
ArgumentNullException . ThrowIfNull ( output ) ;
242
242
243
243
if ( string . Equals ( Type , "importmap" , StringComparison . OrdinalIgnoreCase ) )
244
244
{
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.
247
261
var importMap = ImportMap ?? ViewContext . HttpContext . GetEndpoint ( ) ? . Metadata . GetMetadata < ImportMapDefinition > ( ) ;
248
262
if ( importMap == null )
249
263
{
@@ -252,10 +266,10 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
252
266
return ;
253
267
}
254
268
269
+ output . Content . SetHtmlContent ( importMap . ToString ( ) ) ;
255
270
output . TagName = "script" ;
256
271
output . TagMode = TagMode . StartTagAndEndTag ;
257
272
output . Attributes . SetAttribute ( "type" , "importmap" ) ;
258
- output . Content . SetHtmlContent ( importMap . ToString ( ) ) ;
259
273
return ;
260
274
}
261
275
0 commit comments