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.39k stars 10k forks source link

CLI Hot reload Blazor wasm just doesn't work. #40587

Closed ziaulhasanhamim closed 2 years ago

ziaulhasanhamim commented 2 years ago

Is there an existing issue for this?

Describe the bug

There were many issues about dotnet watch not working with blazor wasm. #38561, #36723, #40091 etc. It was mentioned there that the issue is fixed in .net 6.0.2. But it's not. The issue is there still. Furthermore, there are no responses now on those issues when it was informed that in .net6.0.2 it's not working. Very disappointing behavior.

dotnet watch --verbose logs

watch : Project supports hot reload and was configured to run with the default run-command. Watching with hot-reload
watch : Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload. Press "Ctrl + R" to restart.
watch : Building...
watch : Started 'C:\Program Files\dotnet\dotnet.exe' '' with process id 9496
  Determining projects to restore...
  Restored C:\Users\ziaul\Sources\BlazorWasmApp\BlazorWasmApp.csproj (in 1.39 sec).
  BlazorWasmApp -> C:\Users\ziaul\Sources\BlazorWasmApp\bin\Debug\net6.0\BlazorWasmApp.dll
  BlazorWasmApp (Blazor output) -> C:\Users\ziaul\Sources\BlazorWasmApp\bin\Debug\net6.0\wwwroot
watch : Process id 9496 ran for 27116ms
watch : Running MSBuild target 'GenerateWatchList' on 'C:\Users\ziaul\Sources\BlazorWasmApp\BlazorWasmApp.csproj'
watch : Started 'C:\Program Files\dotnet\dotnet.exe' '' with process id 9176
watch : Process id 9176 ran for 3657ms
watch : Watching 28 file(s) for changes
watch : dotnet-watch is configured to launch a browser on ASP.NET Core application startup.
watch : Configuring the app to use browser-refresh middleware.
watch : Refresh server running at wss://localhost:58192,ws://localhost:58193.
watch : HotReloadProfile: BlazorWebAssembly.
watch : Waiting for a browser to connect
watch : Started 'dotnet' '"C:\Users\ziaul\.nuget\packages\microsoft.aspnetcore.components.webassembly.devserver\6.0.2\build\../tools/blazor-devserver.dll" --applicationpath "C:\Users\ziaul\Sources\BlazorWasmApp\bin\Debug\net6.0\BlazorWasmApp.dll"' with process id 8976
watch : Running dotnet with the following arguments: run
watch : Started
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:7020
watch : Launching browser.
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5152
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Users\ziaul\Sources\BlazorWasmApp
watch : Hot reload capabilities: .
watch : File changed: C:\Users\ziaul\Sources\BlazorWasmApp\Pages\Index.razor.
watch : No deltas modified. Applying changes to clear diagnostics.
watch : Received 1 from browser in [Count: 1, MessageType: Binary, EndOfMessage: True].
watch : No hot reload changes to apply.
watch : Hot reload change handled in 6599.4355ms.

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

6.0.200

Anything else?

No response

javiercn commented 2 years ago

@ziaulhasanhamim thanks for contacting us.

Could you provide a minimal repro project as a public github repository with detailed steps on how to trigger the issue so that we can make progress investigating?

ghost commented 2 years ago

Hi @ziaulhasanhamim. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ziaulhasanhamim commented 2 years ago

Could you provide a minimal repro project as a public github repository with detailed steps on how to trigger the issue so that we can make progress investigating?

dotnet new blazorwasm then dotnet watch --verbose you can see there watch : Hot reload capabilities: . So there are no capabilities for hot reload. Also sometimes it shows watch : Hot reload capabilities: Baseline Then it works well

ghost commented 2 years ago

Thanks for contacting us.

We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

danroth27 commented 2 years ago

you can see there watch : Hot reload capabilities: .

@ziaulhasanhamim How often does this happen for you? I tried these steps several times, but I always ended up with Baseline and hot reload worked fine. Have you noticed anything that might be causing the capabilities to not get identified correctly?

davidivkovic commented 2 years ago

Not sure this is the right place, but figured it would be better than opening a new issue. A similar problem occurs when running dotnet watch for a webapi inside a docker container on wsl2. Works fine on the host Windows machine, but not inside the container. Dotnet version 6.0.201

info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://[::]:80
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /src/
watch : Hot reload capabilities: Baseline AddMethodToExistingType AddStaticFieldToExistingType AddInstanceFieldToExistingType NewTypeDefinition ChangeCustomAttributes UpdateParameters.
watch : File changed: /src/Controllers/WeatherForecastController.cs.
watch : No deltas modified. Applying changes to clear diagnostics.
watch : No hot reload changes to apply.
watch : Hot reload change handled in 25385.07ms.
ziaulhasanhamim commented 2 years ago

@ziaulhasanhamim How often does this happen for you? I tried these steps several times, but I always ended up with Baseline and hot reload worked fine. Have you noticed anything that might be causing the capabilities to not get identified correctly?

Whenever the build takes longer it happens. Maybe it's a timeout problem. I have seen @pranavkm mention that.

danroth27 commented 2 years ago

A similar problem occurs when running dotnet watch for a webapi inside a docker container on wsl2. Works fine on the host Windows machine, but not inside the container.

@davidivkovic I think you should open a separate issue with detailed repro steps for the problem you're seeing. Hot reload is supported in WSL2 and so far we haven't been able to reproduce the issue you're seeing.

ghost commented 2 years ago

Hi @ziaulhasanhamim. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ziaulhasanhamim commented 2 years ago

Open question? What is the question? And why author feedback was added? What feedback do I need to provide?

ghost commented 2 years ago

Thanks for contacting us. We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. Because it's not immediately obvious that this is a bug in our framework, we would like to keep this around to collect more feedback, which can later help us determine the impact of it. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

szalapski commented 2 years ago

I am experiencing this too. "No hot reload changes to apply." is very wrong. It is so close, it just needs to apply the changes to my .razor file, push the new client code etc.

Apollo3zehn commented 2 years ago

Me too, sometimes I get "Hot reload capabilities: Baseline." (hot reload works) and other times I get "Hot reload capabilities: ." (hot reload does not work).

Occasionally it helps to delete all build artifacts and rebuild everything. However, if it is really a build time issue as @ziaulhasanhamim suggested, deleting the build artifacts should make it worse ... its confusing and quite annoying :-(

Edit: I am working under Kubuntu 22.04 using vscode.

ziaulhasanhamim commented 2 years ago

@Apollo3zehn i find that this problem is directly related to build time. When you less build time the hot reload works. But when you have got a larger build time it will surely fail

Apollo3zehn commented 2 years ago

Thanks, I switched from my Windows Notebook to a Kubuntu VM running on that Notebook and of course the build time increased.

I guess it fails silently either here:

https://github.com/dotnet/sdk/blob/94502f47c07d09c215b458b7529341d3981d8ccc/src/BuiltInTools/dotnet-watch/HotReload/DefaultDeltaApplier.cs#L43

Or here: https://github.com/dotnet/sdk/blob/94502f47c07d09c215b458b7529341d3981d8ccc/src/BuiltInTools/dotnet-watch/HotReload/BlazorWebAssemblyDeltaApplier.cs#L63

There is a 10 second timeout specified. Maybe it is related to that.

ziaulhasanhamim commented 2 years ago

Yeah, timeout is maybe the problem https://github.com/dotnet/aspnetcore/issues/38561#issuecomment-979419641. Why there is a need for a timeout. I don't think there is a timeout for Blazor Server or asp.net core. And if the timeout is really needed then give the user the ability to change the duration via environment variables.

iampluque commented 2 years ago

A similar problem occurs when running dotnet watch for a webapi inside a docker container on wsl2. Works fine on the host Windows machine, but not inside the container.

@davidivkovic I think you should open a separate issue with detailed repro steps for the problem you're seeing. Hot reload is supported in WSL2 and so far we haven't been able to reproduce the issue you're seeing.

@davidivkovic Did you open the issue? or resolved it? ... i'm having the exact same issue!

davidivkovic commented 2 years ago

@iampluque

Never resolved the issue. Stopped using dotnet, switched to quarkus.

Apollo3zehn commented 2 years ago

I switched from my Kubuntu 22.04 VM to a native Kubuntu 22.04 system on an Intel NUC 11 Performance. Build is much faster now ... and suddenly hot reload works flawlessly :partying_face:! So I can confirm this issue is related to build times (or to the web app's start-up time).

szalapski commented 2 years ago

Hmm, my web app starts pretty fast... how do I troubleshoot this?

On Fri, Jul 29, 2022 at 10:01 AM Apollo3zehn @.***> wrote:

I switched from my Kubuntu 22.04 VM to a native Kubuntu 22.04 system on an Intel NUC 11 Performance. Build times are much faster now ... and suddenly hot reload works flawlessly πŸ₯³! So I can confirm this issue is related to build times (or to the web app's start-up time).

β€” Reply to this email directly, view it on GitHub https://github.com/dotnet/aspnetcore/issues/40587#issuecomment-1199472044, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUY5MJ3RFJ7TYHIAUIJWN3VWPW2XANCNFSM5QFFYP7A . You are receiving this because you commented.Message ID: @.***>

Apollo3zehn commented 2 years ago

I would first make sure there are no script load errors / connection errors in the browser web tools. IIRC, I had some issues there because the developer certifcate was not trusted in Firefox. One of the scripts is responsible for the hot reload functionality.

Then use dotnet watch instead of dotnet watch run.

If also not working with cleared bin/obj folders, and verbose output (dotnet watch -v) does not print anything useful, my last resort would be to try to build dotnet watch myself and increase the timeout I have linked above. But I don't know if compiling dotnet watch is easy enough.

danroth27 commented 2 years ago

@tmat I hit this issue the first time I ran a new Blazor WebAssembly project with .NET SDK 6.0.400:

~\desktop> dotnet new blazorwasm -o BlazorWasmApp
The template "Blazor WebAssembly App" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore/6.0-third-party-notices for details.

Processing post-creation actions...
Running 'dotnet restore' on C:\Users\user\desktop\BlazorWasmApp\BlazorWasmApp.csproj...
  Determining projects to restore...
  Restored C:\Users\user\desktop\BlazorWasmApp\BlazorWasmApp.csproj (in 6.64 sec).
Restore succeeded.

~\desktop> cd .\BlazorWasmApp\
~\desktop\BlazorWasmApp> code .
~\desktop\BlazorWasmApp> dotnet watch
eload.
  πŸ’‘ Press "Ctrl + R" to restart.
dotnet watch πŸ”§ Building...
  Determining projects to restore...
  All projects are up-to-date for restore.
  BlazorWasmApp -> C:\Users\user\desktop\BlazorWasmApp\bin\Debug\net6.0\BlazorWasmApp.dll
  BlazorWasmApp (Blazor output) -> C:\Users\user\desktop\BlazorWasmApp\bin\Debug\net6.0\wwwroot
dotnet watch πŸš€ Started
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:7104
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5041
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Users\user\desktop\BlazorWasmApp
dotnet watch ⌚ File changed: .\Pages\Index.razor.
dotnet watch ⌚ No hot reload changes to apply.
dotnet watch ⌚ File changed: .\Pages\Index.razor.
dotnet watch ⌚ No hot reload changes to apply.
dotnet watch ⌚ File changed: .\Pages\Counter.razor.
dotnet watch ⌚ No hot reload changes to apply.
info: Microsoft.Hosting.Lifetime[0]
dotnet watch πŸ›‘ Shutdown requested. Press Ctrl+C again to force exit.

The browser UI showed the hot reload check mark, but the app UI didn't actually update.

The 2nd time I ran dotnet watch on the same project it worked fine.

ziaulhasanhamim commented 2 years ago

@danroth27 there might be problems about build times and timeout in blazor wasm hot reload. At first build it took little long so hot reload didn't work. At second build it was comparatively faster so hot reload was working

wocar commented 2 years ago

I confirm that there is a timeout issue regarding build times.

I'm using intel mac, and I have to close everything, and run the backing api's in a remote box, because otherwise my machine will get slow, therefore hot-reload not working. Also I have to run dotnet watch twice. The second one is the one that works.

When it works the output is: dotnet watch πŸ”₯ Hot reload capabilities: Baseline

When it doesn't dotnet watch πŸ”₯ Hot reload capabilities: .

Another thing that might affect hot reload working or not, is the boot time of the application. So I set my startup url to a /blank page.

Combining these two things (remote backing api, /blank page) I manage to get hot-reload working.