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

Multiple builds required #199

Open
sebdesalvador opened this issue Oct 3, 2024 · 3 comments
Open

Multiple builds required #199

sebdesalvador opened this issue Oct 3, 2024 · 3 comments

Comments

@sebdesalvador
Copy link

sebdesalvador commented Oct 3, 2024

Describe the bug
Multiple builds are required before my main css file is generated (usually 2, sometimes 3). Sometimes it doesn't even get generated at all unless I delete all the generated .css files first.
I use SASS, all my .sass files are in a Razor Class Library, I have a general file, under Styles/app.sass, compiled into wwwroot/app.css of the same assembly, and other files are coupled to components for css isolation.
In my main project it's actually broken CSS isolation, I have no idea how to fix it.

To Reproduce
Steps to reproduce the behavior:

  1. Create a simple Blazor Server App
  2. Add a RCL to the solution and reference it from the Blazor project
  3. Move the razor components to the RCL project (keep App.razor and Routes.razor in Blazor project)
  4. Add a reference to AspNetCore.SassCompiler from the RCL project (using ReferenceOutputAssembly="false")
  5. Add necessary references:
  • Router: <Router AppAssembly="typeof(Program).Assembly" AdditionalAssemblies="@( new[] { typeof( MainLayout ).Assembly } )"> (MainLayout.razor lives in the RCL project)
  • Program.cs: app.MapRazorComponents< App >().AddInteractiveServerRenderMode().AddAdditionalAssemblies( typeof( MainLayout ).Assembly );
  1. Add sasscompiler.json to the RCL project with the following content:
{
  "ScopedCssFolders": ["."],
  "Source": "Styles",
  "Target": "wwwroot",
  "Configurations": {
    "Debug": {
      "Arguments": "--style=expanded"
    }
  }
}

Expected behavior
When building, the file wwwroot/app.css should be generated (in the RCL project), and it's never generated on first build. Once it's built a couple of times, the file appears, once it's there, it doesn't always get updated unless I delete it and all other generated css files.

Desktop (please complete the following information):

  • OS: macOS Sonoma 14.6.1
  • IDE: Rider 2024.2.5
@sebdesalvador
Copy link
Author

BlazorSass.zip

Here's a brand new solution where the bug occurs. I will try to get hold of another computer to test there.

@sebdesalvador
Copy link
Author

BlazorSass.zip

Here's a brand new solution where the bug occurs. I will try to get hold of another computer to test there.

I have tested this same solution on another computer (Windows PC, Rider and Visual Studio) and the exact same thing happens.

@sleeuwen
Copy link
Collaborator

Hi @sebdesalvador ,

Thanks for providing the solution that reproduces the problem you're seeing.
I've taken a look at it and noticed that in the sasscompiler.json you added "ScopedCssFolders": ["."], is there a specific reason for this?
The issue is that because you added that setting, the first time it compiles the sass files it sees the Styles folder as a scoped css folder, so it compiles the Styles/app.sass file to Styles/app.css. The second time the sass files are compiled, Styles/app.css is already up to date, so then it will compile Styles/app.sass to wwwroot/css/app.css. This has to do with the order we pass the arguments to the sass compiler.

If you remove the setting for the ScopedCssFolders from the sasscompiler.json, it will include some default directories but not the Styles folder, meaning it will correctly compile the files in the Styles folder to the wwwroot/css folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants