Skip to content

Blazor hot reload of scoped css loses referenced css #42332

@uecasm

Description

@uecasm

Is there an existing issue for this?

  • 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
  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
  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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pillar: Dev Experiencearea-commandlinetoolsIncludes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPIbugThis issue describes a behavior which is not expected - a bug.feature-css-isolationThis issue is related to CSS Isolation featurefeature-dotnetwatchThis issue is related to the dotnet-watch command-line tool (now external)feature-hot-reloadThis issue is related to the Hot Reload feaaturetriaged

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions