@@ -794,6 +794,59 @@ public void ScriptTagHelper_RendersImportMap_FromEndpoint()
794794 Assert . Equal ( importMap . ToJson ( ) , output . Content . GetContent ( ) ) ;
795795 }
796796
797+ [ Fact ]
798+ public void ScriptTagHelper_PreservesExplicitImportMapContent_WhenNoImportMapDefinition ( )
799+ {
800+ // Arrange - this simulates the user's scenario where they provide explicit importmap content
801+ // without using asp-importmap attribute
802+ var context = MakeTagHelperContext (
803+ attributes : new TagHelperAttributeList
804+ {
805+ new TagHelperAttribute ( "type" , "importmap" ) ,
806+ } ) ;
807+
808+ var output = MakeTagHelperOutput ( "script" , attributes : new TagHelperAttributeList ( ) ) ;
809+
810+ var helper = GetHelper ( ) ;
811+ helper . Type = "importmap" ;
812+ // No endpoint with ImportMapDefinition and no asp-importmap attribute
813+ // This should NOT suppress the output, allowing user content to render
814+
815+ // Act
816+ helper . Process ( context , output ) ;
817+
818+ // Assert
819+ Assert . Equal ( "script" , output . TagName ) ; // Tag should not be suppressed
820+ Assert . Equal ( "importmap" , output . Attributes [ "type" ] . Value ) ;
821+ // The output should not be suppressed, allowing user's explicit content to render
822+ Assert . False ( output . IsContentModified ) ; // Content should remain as user provided
823+ }
824+
825+ [ Fact ]
826+ public void ScriptTagHelper_SuppressesOutput_WhenAspImportMapAttributeUsedButNoDefinition ( )
827+ {
828+ // Arrange - this simulates using asp-importmap attribute but having no ImportMapDefinition
829+ var context = MakeTagHelperContext (
830+ attributes : new TagHelperAttributeList
831+ {
832+ new TagHelperAttribute ( "type" , "importmap" ) ,
833+ new TagHelperAttribute ( "asp-importmap" , null ) , // asp-importmap used but no value
834+ } ) ;
835+
836+ var output = MakeTagHelperOutput ( "script" , attributes : new TagHelperAttributeList ( ) ) ;
837+
838+ var helper = GetHelper ( ) ;
839+ helper . Type = "importmap" ;
840+ // No endpoint with ImportMapDefinition but asp-importmap attribute is present
841+ // This should suppress the output since it was intended to be auto-generated
842+
843+ // Act
844+ helper . Process ( context , output ) ;
845+
846+ // Assert - output should be suppressed when asp-importmap is used but no definition found
847+ Assert . Null ( output . TagName ) ; // Tag should be suppressed
848+ }
849+
797850 private Endpoint CreateEndpoint ( ImportMapDefinition importMap = null )
798851 {
799852 return new Endpoint (
0 commit comments