dotnet / dotnet/aspnetcore

Blazor hot reload of scoped css loses referenced css

Open
#42,332 14 comments 4 reactions 0 assignees View on GitHub
area-commandlinetools bug feature-css-isolation feature-hot-reload Pillar: Dev Experience triaged
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

This may be a duplicate of #37592, except that was closed as fixed, and the bug is still present.

When running `dotnet watch` and editing a `.razor.css` file in the main application, it will "reload scoped css" but this discards CSS from referenced libraries.

### Expected Behavior

All CSS should remain loaded.

### Steps To Reproduce

1. Clone https://github.com/uecasm/HotReloadStyles.git
2. Launch with `dotnet watch`
3. Observe that, as expected, the scoped styles from both `Index.razor.css` in the main app and `Component1.razor.css` in the library have been merged, resulting in (including border, padding, and green background):
![image](https://user-images.githubusercontent.com/539951/174922978-79a40bfb-1799-44ce-956f-1caea8e3d41f.png)
4. Simply re-save the `Index.razor.css` file without making any changes.
5. Observe that, not as expected, the `Index.razor.css` styles still apply but the `Component1.razor.css` styles have been lost (no border or padding but still green background):
![image](https://user-images.githubusercontent.com/539951/174923110-83fbb111-7954-4615-b579-04d36c9f912b.png)
6. Press Ctrl-R or relaunch `dotnet watch` and observe that all styles are loaded again.

Possibly also of note is that editing the `Component1.razor.css` file does update the styles if editing `Index.razor.css` has not yet unloaded them, but does not restore them after it has.

### Exceptions (if any)

_No response_

### .NET Version

6.0.300

### Anything else?

```
.NET SDK (reflecting any global.json):
Version: 6.0.300
Commit: 8473146e7d

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19041
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.300\

Host (useful for support):
Version: 6.0.5
Commit: 70ae3df4a6

.NET SDKs installed:
2.1.511 [C:\Program Files\dotnet\sdk]
6.0.200 [C:\Program Files\dotnet\sdk]
6.0.300 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.