dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.5k stars 10.04k forks source link

Collocation JavaScript file breaks Hot Reload #57599

Closed RyouBakura closed 2 months ago

RyouBakura commented 2 months ago

Is there an existing issue for this?

Describe the bug

The mere presence of a collocated Javascript file, e.g. "Home.razor.js" breaks Hot Reload functionality for .css files. However C# Hot Reload is not affected.

Expected Behavior

CSS Hot Reload should work.

Steps To Reproduce

  1. Clone the repo project. It's a fresh Blazor Web App.
Click to expand. It was created with the following settings: devenv_U7PjEbL993
  1. Run the project and change the color property in "Home.razor.css" to see that Hot Reload is working!
  2. Stop debugging.
  3. Add a new file called "Home.razor.js"
  4. Run the project again and change the color property in "Home.razor.css" once more.
  5. You should now see this dialog telling you it went wrong:
devenv_6hPiTE3fNi

Exceptions (if any)

18:19 18.29 HotReloadDestroyer: Scoped CSS file changed: Z:\Dotnet\HotReloadDestroyer\Components\Pages\Home.razor.css 18:19 18.35 HotReloadDestroyer: Building scoped CSS files in project HotReloadDestroyer 18:19 18.59 HotReloadDestroyer: [Error] Building scoped CSS files failed for project HotReloadDestroyer 18:19 18.59 Invalid changes were found. Please refer to the Error List window to fix those issues. 18:19 27.95 HotReloadDestroyer (Web server): Hot reload session complete

.NET Version

9.0.100-preview.7.24407.12

Anything else?

I've encountered this problem in both .NET 8 and .NET 9.

MackinnonBuck commented 2 months ago

Looks like the failing target is ApplyJsModules:

The JS module file '\Components\Pages\Home.razor.js' was defined but no associated razor component or view was found for it

...which gets logged from here. Need to do a bit more digging as to why it's failing.

javiercn commented 2 months ago

@MackinnonBuck I'm pretty sure the cause of this is because there's a target that's not running for JS.

We did a specific thing for CSS hot reload, and not a general thing, so I imagine that when the file gets added, only a subset of the targets needed run and that breaks things.

dgoldm commented 2 months ago

@RyouBakura thanks for pinpointing the issue. Having to restart my app after every change in css was driving me crazy. At least now I can temporarily delete the js file while working on my layouts. I hope this gets fixed ASAP

MrChriZ commented 1 month ago

Is this fix in .NET 9 rc2? As I'm still seeing it.

dgoldm commented 1 week ago

I'm seconding @MrChriZ 's comment. This is still broken. And very annoying.

XorZy commented 2 days ago

The issue is still present in 9.0.100. Please reopen this issue, this is a major inconvenience which makes it nearly impossible to work.