Skip to content

Honor inherited AssetPath attributes on component parameters - #85171

Merged
chsienki merged 1 commit into
dotnet:mainfrom
chsienki:fix/asset-path-inheritance
Sep 9, 2026
Merged

Honor inherited AssetPath attributes on component parameters#85171
chsienki merged 1 commit into
dotnet:mainfrom
chsienki:fix/asset-path-inheritance

Conversation

@chsienki

@chsienki chsienki commented Sep 5, 2026

Copy link
Copy Markdown
Member

AssetPathAttribute has Inherited = true, but component parameter discovery only inspects attributes declared directly on the selected property. An override that redeclares [Parameter] therefore loses the base property's asset-path opt-in and leaves ~/ literals unexpanded.

Follow the OverriddenProperty chain when resolving [AssetPath]. This preserves attribute inheritance for overrides without applying the opt-in to hidden properties. Add an integration baseline covering a base virtual parameter with [AssetPath] and a derived override that redeclares only [Parameter].

Addresses #84796 (comment)

Microsoft Reviewers: Open in CodeFlow

AssetPathAttribute applies to property overrides, but tag helper discovery
only checks attributes declared directly on the selected property. Follow the
overridden-property chain so derived component parameters retain the opt-in
without affecting hidden properties.

Add integration coverage for an override that redeclares Parameter while
inheriting AssetPath.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: dd15ad81-c929-4d0c-91de-354c0c777533
Copilot AI lite review requested due to automatic review settings September 5, 2026 01:17
@chsienki
chsienki requested a review from a team as a code owner September 5, 2026 01:17
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The override-chain attribute resolution change is narrowly scoped and is covered by an integration regression test with baselines validating the expanded output.

Pull request overview

This PR fixes component-parameter asset-path opt-in detection so [AssetPath] applied on a base virtual parameter is still honored when a derived component overrides the property and redeclares only [Parameter], ensuring ~/ literals are expanded as intended.

Changes:

  • Update component parameter discovery to treat [AssetPath] as inherited across the OverriddenProperty chain.
  • Add an integration regression test + baselines covering [AssetPath] on a base virtual parameter with a derived override that redeclares [Parameter].
  • Preserve prior behavior for hidden (new) properties by only following true overrides.
File summaries
File Description
src/Razor/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/TagHelpers/Producers/ComponentTagHelperProducer.cs Detects [AssetPath] by walking OverriddenProperty to honor attribute inheritance for overrides.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs Adds TildePath_ComponentParam_InheritedAssetPath regression test validating the new behavior end-to-end.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentCodeGenerationTest/TildePath_ComponentParam_InheritedAssetPath/TestComponent.mappings.txt New baseline for source↔generated mappings for the inherited-[AssetPath] scenario.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentCodeGenerationTest/TildePath_ComponentParam_InheritedAssetPath/TestComponent.ir.txt New baseline validating IR contains Assets[@"..."] expansion for the component parameter.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentCodeGenerationTest/TildePath_ComponentParam_InheritedAssetPath/TestComponent.decl.ir.txt New baseline for declaration IR for the scenario.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentCodeGenerationTest/TildePath_ComponentParam_InheritedAssetPath/TestComponent.decl.codegen.cs New baseline for declaration codegen output.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentCodeGenerationTest/TildePath_ComponentParam_InheritedAssetPath/TestComponent.codegen.cs New baseline for implementation codegen output showing the expanded Assets[@"..."] expression.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentCodeGenerationTest/TildePath_ComponentParam_InheritedAssetPath/TestComponent.builder.txt New baseline for the render-tree builder steps reflecting the expanded value.
Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 0
  • Review effort level: Lite

@chsienki
chsienki merged commit c548519 into dotnet:main Sep 9, 2026
25 checks passed
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants