Skip to content

Isolated CSS Files are not applied, unable to restore behaviour that originally worked with CSS files #64390

@codeputer

Description

@codeputer

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The CSS bundle appears to exist and load, but the browser does not apply the styles. If the same rules are applied to an inline style or a global stylesheet (site.css), the styles work.

This setup worked earlier in the same project and stopped working while fixing other bugs. I have not been able to restore the previous behaviour. When creating a new project, they will work as well.

Environment

  • .NET: 10.0 (Blazor United style project)
  • Rendering: Interactive server
  • Browser: Microsoft Edge (and others, same result)
  • Project: Blazor app with isolated CSS (Component.razor + Component.razor.css)

Program.cs (simplified)

if (app.Environment.IsDevelopment())
{
    app.UseStaticFiles();
}
else
{
    app.MapStaticAssets();
}

app.MapStaticAssets();

app.MapRazorComponents<App>()
   .AddInteractiveServerRenderMode();

Repro steps

  1. Create a Blazor United project on .NET 10.
  2. Add a component with isolated CSS, for example:
    1. Home.razor
    2. Home.razor.css
  3. Run the app in Development.
  4. Open the page that uses Home.razor.
  5. Inspect the page in devtools.
    1. The scoped CSS bundle appears present in the project output.
    2. The CSS file seems to load.
  6. The component renders without the expected isolated styles.
  7. Move the same CSS rules from Home.razor.css into:
    1. Inline style on the element, or
    2. A global stylesheet (site.css).
  8. Reload the page.
  9. Styles now apply as expected.

Expected Behavior

Expected behavior

  • Isolated CSS (Component.razor.css) should apply to the matching component when the page loads, both in Development and Production.
  • If the CSS file loads and the rules are valid, the component should render with the isolated styles, without requiring inline or global CSS as a workaround.

Steps To Reproduce

  1. Create a Blazor United project on .NET 10.
  2. Add a component with isolated CSS, for example:
    1. Home.razor
    2. Home.razor.css
  3. Run the app in Development.
  4. Open the page that uses Home.razor.
  5. Inspect the page in devtools.
    1. The scoped CSS bundle appears present in the project output.
    2. The CSS file seems to load.
  6. The component renders without the expected isolated styles.
  7. Move the same CSS rules from Home.razor.css into:
    1. Inline style on the element, or
    2. A global stylesheet (site.css).
  8. Reload the page.
  9. Styles now apply as expected.

Exceptions (if any)

None found

.NET Version

10

Anything else?

the isolated CSS files were working, and something happened that caused them to stop working. I have worked at this for at least 8 hours - rebooting, remove obj/bin directors, browser hard refresh and cache, deployed to Azure, all resulted in no CSS being applied.

  • Scoped CSS output exists under obj/Debug/net10.0/scopedcss.
  • The issue looks like a regression in how isolated CSS is wired into the pipeline or referenced from the rendered page.
  • I am open to running additional diagnostics, for example exact HTML link tags or network details, if guidance is provided.
Image Image Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions