Skip to content

Blazor empty template doesn't load scoped CSS #43975

Closed
@SteveSandersonMS

Description

@SteveSandersonMS

The new empty template does not contain a tag like this in index.html:

<link href="MyProjectName.styles.css" rel="stylesheet" />

... and so, by default, scoped CSS is not loaded or applied. Obviously people can add this manually, but it's very nonobvious, and breaks many docs/tutorials that tell you that scoped CSS just works without further manual steps. For example you might add a reference to QuickGrid and expect its built-in styles to show up automatically, but they won't unless you add this hard-to-know-about tag.

You could argue that this is by design because the "empty" template is, well, empty. But we have to strike a balance between emptiness and usability, and in this specific case, I think the surprisingness of this problem and the nonobviousness of the solution would land us on the side of wanting it to work by default.

Solution

This is a bit awkward to solve because we can't simply add that <link> tag to the template. Until your project contains some scoped CSS, you'd get a 404 for that file.

Ideally we would serve an empty file rather than a 404, and then the template could contain the <link> tag by default. People who don't want to use scoped CSS at all can simply remove the tag.

Metadata

Metadata

Labels

area-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing one

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions