-
Notifications
You must be signed in to change notification settings - Fork 10.4k
[Blazor] Wire up CSS isolation for the current project #24221
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
Conversation
javiercn
commented
Jul 22, 2020
- Works E2E
- Needs cleanups
- Needs tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
...icrosoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.CssIsolation.targets
Outdated
Show resolved
Hide resolved
src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Sdk.Razor.CurrentVersion.targets
Outdated
Show resolved
Hide resolved
...icrosoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.CssIsolation.targets
Outdated
Show resolved
Hide resolved
...icrosoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.CssIsolation.targets
Outdated
Show resolved
Hide resolved
src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Pages/FetchData.razor
Outdated
Show resolved
Hide resolved
src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Pages/FetchData.razor.css
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great
...r/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.ScopedCss.targets
Outdated
Show resolved
Hide resolved
@@ -64,6 +64,9 @@ Copyright (c) .NET Foundation. All rights reserved. | |||
<!-- Controls whether or not the static web assets feature is enabled. By default is enabled for netcoreapp3.0 | |||
applications and RazorLangVersion 3 or above. --> | |||
<StaticWebAssetsEnabled Condition="'$(StaticWebAssetsEnabled)' == ''">$(_Targeting30OrNewerRazorLangVersion)</StaticWebAssetsEnabled> | |||
|
|||
<!-- Controls whether or not the scoped css feature is enabled. By default is enabled for net5.0 applications and RazorLangVersion 5 or above --> | |||
<ScopedCssEnabled Condition="'$(ScopedCssEnabled)' == ''">$(_Targeting30OrNewerRazorLangVersion)</ScopedCssEnabled> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be 5.0 or newer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't get this to work, Wasm.Authentication.Client was complaining about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
had to pass /p:ScopedCssEnabled to make it work. I'll revisit later on, but we could fix it after preview8 if necessary
@@ -269,7 +269,7 @@ public void Fails_WhenStaticWebAsset_HaveDifferentSourceId() | |||
Assert.Equal(expectedError, message); | |||
} | |||
|
|||
[Fact] | |||
[Fact(Skip = "https://github.com/dotnet/aspnetcore/issues/24257")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to relax this restriction. The issue is for future follow-up
<Target Name="_AddBundleToStaticWebAssetsPublishedFile" Condition="'$(ScopedCssDisableBundling)' != 'true' and '@(_AllScopedCss)' != ''" BeforeTargets="_StaticWebAssetsComputeFilesToPublish" DependsOnTargets="_CollectAllScopedCssAssets"> | ||
<ItemGroup> | ||
<!-- Manually add the file to the publish flow. See https://github.com/dotnet/aspnetcore/issues/24245 --> | ||
<_ExternalPublishStaticWebAsset Include="$(_ScopedCssOutputFullPath)"> | ||
<SourceType>generated</SourceType> | ||
<SourceId>$(PackageId)</SourceId> | ||
<ContentRoot>$(_ScopedCssIntermediatePath)</ContentRoot> | ||
<BasePath>$(StaticWebAssetBasePath)</BasePath> | ||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> | ||
<RelativePath>$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)',$([MSBuild]::NormalizePath('wwwroot/$(StaticWebAssetBasePath)/_framework/scoped.styles.css'))))</RelativePath> | ||
</_ExternalPublishStaticWebAsset> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="_AdjustIsolatedCssPackageContents" BeforeTargets="_RemoveWebRootContentFromPackaging;_CreateStaticWebAssetsCustomPropsCacheFile" DependsOnTargets="_CollectAllScopedCssAssets"> | ||
<ItemGroup> | ||
<_CurrentProjectStaticWebAsset Remove="$(_ScopedCssOutputFullPath)" /> | ||
<StaticWebAsset Remove="$(_ScopedCssOutputFullPath)" /> | ||
<StaticWebAsset Include="@(_AllScopedCss)" Condition="'%(SourceType)' == ''" /> | ||
</ItemGroup> | ||
</Target> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part gets a bit tricky due to the lack of support for assets representing generated content. #24245 will address that.
// can update the Content item for the .razor.css file with Scoped=false and we will not consider it. | ||
foreach (var unmatched in unmatchedScopedCss) | ||
{ | ||
Log.LogError($"The scoped css file '{unmatched.ItemSpec}' was defined but no associated razor component was found for it."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do this in a follow up, but it's useful to include an error code with these errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be an acceptable error code? I tried to search for previous history on this but couldn't find anything.
{ | ||
var componentCandidate = RazorComponents[i]; | ||
var j = 0; | ||
while (j < unmatchedScopedCss.Count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
return builder.ToString(); | ||
} | ||
|
||
private string ToBase36(byte[] hash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private string ToBase36(byte[] hash) | |
private string ToBase36(byte[] hash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* Wires up CSS isolation on the build. * Transforms the css files during build. * Bundles all scopes css into a single file and exposes it on _framework/scoped.styles.cs * Packs pre-processed files as static web assets.