Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot Reload with dotnet-watch and Blazor WebAssembly fails on simple markup .razor changes with "No hot reload changes to apply." in .NET 7 and "not supported by the runtime" in .NET 8 RC2. #51781

Closed
1 task done
szalapski opened this issue Oct 31, 2023 · 11 comments
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) feature-hot-reload This issue is related to the Hot Reload feaature

Comments

@szalapski
Copy link

szalapski commented Oct 31, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Please get Hot Reload to work reliably and consistently with dotnet watch (and in VS Pro debugging) with Blazor WebAssembly, especially with changes to .razor files. This feature seems so buggy when it should "just work". It seems to work much better with non-Blazor server-side changes, e.g. to a Web API, but that's not where much productivity benefit would result.

When using dotnet watch on my Server project, with verbose logging, on a change, I always get No hot reload changes to apply. in .NET 7 and "No changes applied to client because they are not supported by the runtime." in .NET 8 RC2. This is on a solution that was created with .NET 6 and upgraded to 7 then 8.

The following issues were closed without fixing the issue: 47836 and The earlier issue 45519, which has links to many other similar issues too, but I will avoid repeating them here.

So @danroth27 reached out on Twitter so I thought I would try again with this one. Please help fix!

Expected Behavior

If I get "No hot reload changes to apply.", please tell me why. It sees a file change but doesn't see changes to apply--why not??? Even in verbose mode, I get no clues.

But really, I just want hot reload to work as designed. I expect to see dotnet watch ⌚ File changed: .\TradeCars\Client\Pages\Index.razor. and then the new page is injected and the DOM/other updates happen live in my browser--or it is a rude edit and dotnet-watch rebuilds and reloads. Not getting either right now.

Steps To Reproduce

Sample repo for .NET 7 and a branch for .NET 8 RC2

To reproduce, run exactly as follows

git clone https://github.com/szalapski/HotReloadIssue45519Demo
cd .\HotReloadIssue45519Demo\
dotnet watch --project ./TradeCars/Server

I got a lot of irrelevant info output, but after I edit Index.razor and save it, I get:

dotnet watch ⌚ File changed: .\TradeCars\Client\Pages\Index.razor.
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/2 POST https://localhost:5008/_framework/blazor-hotreload application/json 2
dotnet watch ⌚ No hot reload changes to apply.
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/2 POST https://localhost:5008/_framework/blazor-hotreload application/json 2 - 2

I have .NET SDK 7.0.403 running on Windows 10. @tmat said he could not reproduce even with the above repo--if that is still the case, there must be something different about our environments; will you help me figure it out? What could be different in your run? What output do you see? This is plaguing my whole team and preventing further adoption of Blazor at my large company.

I tried it with SDK 8.0.100-rc.2.23502.2 (in other branch - git switch dotnet8) and target framework net8.0, and got:

dotnet watch ⌚ File changed: .\TradeCars\Client\Pages\Index.razor.
dotnet watch ⌚ No changes applied to client because they are not supported by the runtime.
dotnet watch ⌚ Received successful apply from delta applier.
dotnet watch 🔥 Hot reload of changes succeeded.
dotnet watch ⌚ Refreshing browser.
dotnet watch 🔥 Hot reload change handled in 865.0203ms.

Though it seemed more promising at first glance, there is no net change even though the dotnet-watch console message changed and it still doesn't work for the simplest of changes. "They are not supported by the runtime"? Why?

.NET Version

7.0.403 and 8.0.100-rc.2.23502.2

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label Oct 31, 2023
@szalapski szalapski changed the title Hot Reload with dotnet-watch and Blazor WebAssembly fails with "No hot reload changes to apply." Hot Reload with dotnet-watch and Blazor WebAssembly fails with "No hot reload changes to apply." in .NET 7 and "not supported by the runtime" in .NET 8 RC2. Oct 31, 2023
@szalapski szalapski changed the title Hot Reload with dotnet-watch and Blazor WebAssembly fails with "No hot reload changes to apply." in .NET 7 and "not supported by the runtime" in .NET 8 RC2. Hot Reload with dotnet-watch and Blazor WebAssembly fails on simple markup .razor changes with "No hot reload changes to apply." in .NET 7 and "not supported by the runtime" in .NET 8 RC2. Nov 1, 2023
@danroth27 danroth27 added feature-hot-reload This issue is related to the Hot Reload feaature feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) labels Nov 3, 2023
@MakiseKurisu
Copy link

Do you get something like Firefox can’t establish a connection to the server at wss://localhost:36843/. in your browser console? I think this might be the reason Hot Reload is not working (for me). Although I can see the port is open with nmap and it is the correct port reported by dotnet watch -v.

@MakiseKurisu
Copy link

What I found out is that if I only have Firefox to view the Blazor WASM project, Hot Reload no matter if I get the cert trusted or not. However, if I can open Chromium to open the project first (thus register Hot reload capabilities), I can have Hot Reload working on both Chromium (manually navigate to the project page) and Firefox (automatically since it is the default browser for me). BUT, if I then refresh the page in both browser, Firefox's Hot Reload will stop working, while Chromium could still work.

@szalapski
Copy link
Author

szalapski commented Nov 6, 2023

@MakiseKurisu, I tried it with both Firefox and Google Chrome just to be sure and both match the behavior I cite above, with no "can’t establish a connection to the server" message at all. Indeed, the browser properly has a connection to the server, as I have seen the grey check popover, yet the hot "re-compile" (or partial recompile with injection) didn't happen, so the browser never shows the change, per the above.

Care to try it with my repo and see what you get, per the instructions above?

@andrewaggb
Copy link

I have nothing but problems with hot reload and .net 8 hasn't fixed that for me. I end up having to stop start my projects which is so tedius because they're large and can take a couple seconds to compile/startup etc and then navigate back to where I was... I've tried dotnet watch and visual studio. It seems to work for css and js files but it seems to not work razor files at all, even if all I change is just html. I saw the previous thread that @szalapski had started and I really can't upvote this enough.

@szalapski
Copy link
Author

szalapski commented Nov 18, 2023

I have nothing but problems with hot reload and .net 8 hasn't fixed that for me. ...I saw the previous thread that @szalapski had started and I really can't upvote this enough.

Would you be willing to try my repo according to the short instructions I gave above? I'm curious if you could get a different outcome from me.

@andrewaggb
Copy link

I tried the repro and it didn't work for me either (the .net rc2 version). Hot reload failed to detect the changes.
then I updated all the nugets in the projects to the release version for .net 8 and the repo from @szalapski did work and hot reload was working.

But... I came here because hot reload has never really worked for me. I already updated all my packages to .net 8.

I just did a dotnet watch test just now and it's working. I have no words. Maybe I've only run the production .net 8 build from visual studio so far and maybe something was fixed from rc2 to prod in .net watch. Or maybe it only worked because I only changed some simple things and it'll break in an hour...

Honestly I'll try it for the next few days and post back my experience.

@szalapski
Copy link
Author

szalapski commented Nov 21, 2023

I'm delighted to say that I get the same result--what didn't work in the beta now somewhat works with SDK 8.0.100 RTM! Many thanks and kudos to @danroth27, @tmat, and anyone else who may have contributed to improve this. I say "Somewhat" because I frequently get full rebuilds even on mere .razor markup changes, but at least it all works!

Would anyone have the time to tell us what the issue was? So far it seems like it was partially fixed in the prerelease and fully fixed in RTM, but I still have no idea what the problem was or why ASP.NET 8 fixes it. It will help me to be aware if similar or related issues come up in the future.

@andrewaggb I'm going to close this issue as it fixes the sample repo above (which is now updated in main with the working version). I'll support a new issue if you make one, but you might want to provide a minimal repo that reproduces the problem.

@tmat
Copy link
Member

tmat commented Nov 21, 2023

I say "Somewhat" because I frequently get full rebuilds even on mere .razor markup changes, but at least it all works!

Does dotnet watch --verbose print any errors/rude edits related to the modified .razor page that would explain why the rebuild was triggered?

If not you can also set an env variable like so and share the generated logs dir, so we can take a look:
set Microsoft_CodeAnalysis_EditAndContinue_LogDir=D:\Temp\logs

@tmat
Copy link
Member

tmat commented Nov 21, 2023

Would anyone have the time to tell us what the issue was?

Likely a race condition fixed here: dotnet/sdk#33007

@szalapski szalapski reopened this Nov 22, 2023
@szalapski
Copy link
Author

szalapski commented Nov 22, 2023

Sorry, still getting the problem--no longer in the repo above, but in my main project I still get 🔥 Hot reload capabilities: . and No hot reload changes to apply. Could we stay on it, @tmat?

With .NET 8, and verbose on sadly, I still get:

Now listening on: https://localhost:5001
dotnet watch ⌚ Launching browser.
Application started. Press Ctrl+C to shut down.
dotnet watch 🔥 Hot reload capabilities: .
dotnet watch ⌚ File changed: .\MySoln\Client\Components\PageParts\MyBigComponent.razor.
dotnet watch ⌚ No deltas modified. Applying changes to clear diagnostics.
dotnet watch ⌚ Received 1 from browser in [Count: 1, MessageType: Binary, EndOfMessage: True].
dotnet watch ⌚ No hot reload changes to apply.
dotnet watch 🔥 Hot reload change handled in 9141.2595ms.

Thanks for your theory, @tmat. I will try to get a repo that reproduces it but it might be tough. Any ideas to overcome? Any way to delay one side of the race you have in mind? Or can we somehow add verbose output when there is Hot reload capabilities: . as to why it couldn't get any capabilities?

@mkArtakMSFT
Copy link
Member

We think the remaining issue that you're facing is addressed by dotnet/sdk#36195, which I believe should ship in the upcoming 8.0.1 patch in January. If after updating to that new SDK you still face the issue, please file a new issue, so that we can investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) feature-hot-reload This issue is related to the Hot Reload feaature
Projects
None yet
Development

No branches or pull requests

6 participants