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 for Blazor #5456

Closed
1 of 4 tasks
Tracked in core#5510 #27883
danroth27 opened this issue Jan 25, 2018 · 144 comments
Closed
1 of 4 tasks
Tracked in core#5510 #27883

Hot Reload for Blazor #5456

danroth27 opened this issue Jan 25, 2018 · 144 comments

Comments

@danroth27
Copy link
Member

@danroth27 danroth27 commented Jan 25, 2018

@SteveSandersonMS
Copy link
Member

@SteveSandersonMS SteveSandersonMS commented Mar 16, 2018

See dotnet/blazor#193 for status updates on this work item.

@martasp
Copy link

@martasp martasp commented Mar 23, 2018

For now, we can use dotnet watch run and recompile every time when the change occurs.
Just using this in csproj file :
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
<Watch Include="**\*.cshtml"/>

@danroth27
Copy link
Member Author

@danroth27 danroth27 commented Apr 4, 2018

We've hit a snag with live reload for 0.2.0, so moving this out until we can work through a more robust design.

@ghost
Copy link

@ghost ghost commented Sep 6, 2018

Hi, I'm using dotnet sdk 2.2.100-preview1-009349 and blazor 0.5.1 under Mac.
Live reload doesn't work using "dotnet blazor serve". If I change some html markup in a cshtml file, the app doesn't reload itself and ever after a manual browser reload, the app display the old html content. How can I solve this?

@mkArtakMSFT
Copy link
Contributor

@mkArtakMSFT mkArtakMSFT commented Mar 20, 2019

@danroth27, what's #4056 then? Should it be closed?

@dazinator
Copy link

@dazinator dazinator commented May 11, 2019

Few questions!
1 Does this track live reload for both server side blazor and client side blazor?
2. Will live reload ship in go live release (i.e in net core 3.0) ?
3. Will live reload mechanism lose page state (I.e equivalent to an f5 refresh) or will it behave similar to Hot Module Replacement in javascript land - I.e only the changed Components UI will re-render? If the latter, will there be a mechanism to preserve component state on the client between updates?

@danroth27
Copy link
Member Author

@danroth27 danroth27 commented May 13, 2019

Does this track live reload for both server side blazor and client side blazor?

Yes

Will live reload ship in go live release (i.e in net core 3.0) ?

For .NET Core 3.0 we expect to support auto rebuild based on file changes, but you will still need to manually refresh the browser.

Will live reload mechanism lose page state (I.e equivalent to an f5 refresh) or will it behave similar to Hot Module Replacement in javascript land - I.e only the changed Components UI will re-render? If the latter, will there be a mechanism to preserve component state on the client between updates?

We don't currently have a plan for supporting hot module replacement in a way that preserves client state.

@SteveSandersonMS
Copy link
Member

@SteveSandersonMS SteveSandersonMS commented May 14, 2019

We don't currently have a plan for supporting hot module replacement in a way that preserves client state.

At least, not automagically. Theoretically if you follow a Redux-like architecture, or anything else that strictly decouples state from display, then you could serialize that state out before unload and restore on reload. However this isn't something we're planning to bake in as a feature, as not everyone wants to follow that kind of architecture.

@dazinator
Copy link

@dazinator dazinator commented May 14, 2019

then you could serialize that state out before unload and restore on reload.

Thanks. Please, once ready, would you be able to document the appropriate hooks (before unload / reload etc) provided in the design to facilitate this. I'd like to start on an implementation / helper nuget package to enable this pattern for those that want it!

@ahmad2smile
Copy link

@ahmad2smile ahmad2smile commented May 26, 2019

Couldn't get the dotnet watch run to work, tried following and other options too,

dotnet watch --project "Portfolio.Client" run --project "Portfolio.Server"

Just ended up with the following crude solution using nodemon:

npx nodemon --watch "Portfolio.Client" -e razor,css,html,cs --exec 'dotnet run --project "Portfolio.Server"'

@yberstad
Copy link

@yberstad yberstad commented May 30, 2019

I thought i was supposed to run:
dotnet watch --project BlazorTest.Client run
But that gave me an error.

If I used:
dotnet watch --project BlazorTest.Server run

With the following in the project BlazorTest.Server.csproj file:

<ItemGroup>
    <Watch Include="..\**\*.razor" />
    <Watch Include="..\**\*.scss" />
    <Watch Include="..\**\*.cs" />
</ItemGroup>

It picked up changes in the BlazorTest.Client project and restarted the server, so I only had to do a manual refresh in the browser.

@dazinator
Copy link

@dazinator dazinator commented May 30, 2019

It picked up changes in the BlazorTest.Client project and restarted the server, so I only had to do a manual refresh in the browser.

Does that mean the server restarts everytime there is a a css, html change?

@yberstad
Copy link

@yberstad yberstad commented May 30, 2019

@dazinator, yes :-)

@dazinator
Copy link

@dazinator dazinator commented May 30, 2019

.. ok just checking but that is a bad thing right? I.e server restart should be unnecessary for a html or css file change as a browser refresh (with cache invalidated) should suffice?

@yberstad
Copy link

@yberstad yberstad commented May 30, 2019

You are right, that is not necessary. Just add or remove the file extensions you are interested in within the <ItemGroup>. Updated my answer to avoid confusion.

@datvm
Copy link

@datvm datvm commented Jun 8, 2019

Sorry if off-topic, is there anyway to live reload from Visual Studio right now (Blazor client-side)? Right now for every change excluding wwwroot files, I have to Build the project (Ctrl Shift B) and reload the browser. Would be wonderful if VS can auto build on saving changes.

@myrup
Copy link

@myrup myrup commented Nov 16, 2020

For what its worth, we are very excited about Blazor and props to the development team. But we are waiting until stateful hot reload is available.

@danroth27
Copy link
Member Author

@danroth27 danroth27 commented Nov 16, 2020

@MussaratAziz Do you also see similar issues if you run your project from the command-line using dotnet watch run?

If the auto refresh functionality is still not working for you in VS, please file a VS feedback issue so it gets tracked appropriately on the VS side.

@MussaratAziz
Copy link

@MussaratAziz MussaratAziz commented Nov 17, 2020

@danroth27 Thanks for the reply dotnet watch run works. Its just VS side. My next action is to uninstall VS then try again. If not I will file VS feedback issue. @tomekjaworski thanks for your suggestion I have tried that before its just doesn't seems to work.

@DamianEdwards DamianEdwards changed the title Hot reload for Blazor Hot Reload for Blazor Nov 19, 2020
@DamianEdwards DamianEdwards added this to Proposed in .NET 6.0 Nov 19, 2020
@hannespreishuber
Copy link

@hannespreishuber hannespreishuber commented Nov 22, 2020

PM> dotnet watch run
dotnet : It was not possible to find any compatible framework version

-16.8.2 .NET

also not working in VS

@BrunoBlanes
Copy link

@BrunoBlanes BrunoBlanes commented Nov 23, 2020

@hannespreishuber that is a terrible way to provide feedback if that was your intent. Try opening an issue and following the template.

@Filipowicz251
Copy link

@Filipowicz251 Filipowicz251 commented Nov 23, 2020

USE LIVESHARP... can’t believe a kid in his basement managed to do something that Microsoft can’t.

Edit: sorry don’t get me wrong, Microsoft has done a terrific job.. but this feature is a must ... just to change a DIV or an attribute is like 45 secs minimum

Just small feedback regarding this statement. For me and using "Auto build and refresh option" (what @porkopek suggested) is taking more like 5 secs. Yes, it is not 1 sec as with Livesharp but it is quite fast and it is working :)

I did try Livesharp, but for me it was breaking the external JS on the site (I did have some slider revolution part and after livesharp was sending an update, the js on the site was broken)

@mrlife
Copy link

@mrlife mrlife commented Nov 23, 2020

something we're looking in to adding support for very soon.

@pranavkm @jongalloway Possible to update the VS Mac roadmap?

@szalapski
Copy link

@szalapski szalapski commented Nov 23, 2020

Hmmm, auto-refreshing the browser in .NET 5 using dotnet watch run doesn't seem to be working for me. I used to use Westwind.AspNetCore.LiveReload, but I have removed it to try this out. When I make a change, the app rebuilds and restarts web server for me, but the browser doesn't refresh. This is a project I upgraded from .NET Core 3.1. Is there anything that needs to be done in startup.cs to enable this? What else could be interfering? How can I troubleshoot?

@BrunoBlanes
Copy link

@BrunoBlanes BrunoBlanes commented Nov 23, 2020

@szalapski Have you noticed if the browser isn't refreshing before the server finishes starting up? I've seen that happen a few times. I don't know if it is by design.

@danroth27
Copy link
Member Author

@danroth27 danroth27 commented Dec 1, 2020

@szalapski Does auto refresh work if you start from a new project? Have you set "launchBrowser": true in launchSettings.json?

@gojanpaolo
Copy link

@gojanpaolo gojanpaolo commented Dec 1, 2020

dotnet watch run also just stops working for me sometimes. Closing all VS instances and then rerunning dotnet watch run seems to solve the issue. I'll see if I can drill down the root cause.

@danroth27
Copy link
Member Author

@danroth27 danroth27 commented Dec 1, 2020

For folks hitting issues with dotnet watch run please open new GitHub issues with any details you have about how to reproduce the problem, so that we don't conflate those investigations with the hot reload work we're working on for .NET 6.

@dotnet dotnet locked as off-topic and limited conversation to collaborators Dec 1, 2020
@Pilchie Pilchie moved this from Proposed to Committed in .NET 6.0 Jan 6, 2021
@mkArtakMSFT mkArtakMSFT removed this from the Next sprint planning milestone Aug 10, 2021
@mkArtakMSFT mkArtakMSFT added this to the 6.0.0 milestone Aug 10, 2021
@mkArtakMSFT
Copy link
Contributor

@mkArtakMSFT mkArtakMSFT commented Sep 16, 2021

Closing this issue as we're done with the work we planned to deliver for 6.0.
There are still many improvements to do in this area which are going to be tracked as part of dotnet/runtime#57365

.NET 6.0 automation moved this from Committed to Completed Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.