Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling blazor css scopes without disabling bundling of .razor.css files #46466

Open
zotanmew opened this issue Feb 2, 2025 · 3 comments
Labels
Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch untriaged Request triage from a team member

Comments

@zotanmew
Copy link

zotanmew commented Feb 2, 2025

Is your feature request related to a problem? Please describe.

I'm trying to disable CSS isolation (attribute scopes), while still colocating stylesheets with my components. Setting <ScopedCssEnabled>false</ScopedCssEnabled> turns the CSS bundling off altogether, which is not useful in this case.

Describe the solution you'd like

A new MSBuild property that allows disabling just scoping, or one that re-enables bundling when scoping has been disabled.

Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Feb 2, 2025
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@zotanmew
Copy link
Author

zotanmew commented Feb 2, 2025

I found a workaround, but it'd be great to have this option added upstream.

<!-- Disables css isolation but keeps bundling of colocated styles enabled -->
<!-- See https://github.com/dotnet/sdk/issues/46466 for more details -->
<Target Name="LoadColocatedCss" BeforeTargets="BundleScopedCssFiles">
    <ItemGroup>
        <_DiscoveredScopedCssFiles Remove="@(_DiscoveredScopedCssFiles)" />
        <_DiscoveredScopedCssFiles Include="@(_ScopedCss)" />
    </ItemGroup>
</Target>

<Target Name="RemoveScopesPre" BeforeTargets="ResolveCssScopes">
    <ItemGroup>
        <RazorComponentActual Include="@(RazorComponent)" />
        <RazorGenerateActual Include="@(RazorGenerate)" />
    </ItemGroup>
</Target>

<Target Name="RemoveScopesPost" AfterTargets="ResolveCssScopes">
    <ItemGroup>
        <RazorComponent Remove="@(RazorComponent)" />
        <RazorGenerate Remove="@(RazorGenerate)" />
        <RazorComponent Include="@(RazorComponentActual)" />
        <RazorGenerate Include="@(RazorGenerateActual)" />
    </ItemGroup>
</Target>

@marcpopMSFT marcpopMSFT added the Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

2 participants