elmish / hmr

Hot Module Replacement for Elmish apps
https://elmish.github.io/hmr
Other
28 stars 8 forks source link

App locks with HMR > 3.0, but works with < 3.0 #12

Closed cmeeren closed 5 years ago

cmeeren commented 5 years ago

Description

I have a problem where if I use version 3 of the HMR nuget, the app locks after the first HMR update after I have made state changes, whereas with version 2, it works fine.

Repro code

Repro solution: fulma-demo.zip

(Not minimal, it's a slightly modified version of https://github.com/MangelMaxime/fulma-demo where I've replaced the app contents with a TodoMVC sample. Contains a lot of dead code from the fulma demo; only the code in src/App.fs is relevant.)

  1. Run fake build -t Watch
  2. Open localhost:8080
  3. Make any Elmish model change (e.g. write in the text field)
  4. Make a change in src/App.fs that should be visible with HMR (e.g. replace "TodoMVC" near the bottom with another string)
  5. Observe HMR works
  6. Now open paket.dependencies and remove < 3 from nuget Fable.Elmish.HMR < 3
  7. Run paket update
  8. Remove |> Program.withHMR from src/App.fs
  9. Repeat 1–5, notice how that the app is locked and won't respond to input.
cmeeren commented 5 years ago

In fact, it seems to be possible to repro this just using the standard https://github.com/MangelMaxime/fulma-demo without my modifications to the app code.

MangelMaxime commented 5 years ago

Ok I think I know the reason.

To detect the HMR in the lazyView we use if isNull Browser.window?HMR_Count then but it seems like isn't set...

I don't know why i got it setted in my test app.

MangelMaxime commented 5 years ago

Ah ooops....

HMR_Count is something coming from my debug app when I was debugging the HMR problems. Will include it in the library nice catch ^^

cmeeren commented 5 years ago

nice catch ^^

Just a lucky break, really. Trying to get the Fulma demo to run on Electron, but I have almost no idea what I'm doing. Pure coincidence that I tracked this down to the version of Fable.Elmish.HMR. Can't even remember now (an hour later) how that happened. Happy to help in any case. :)

MangelMaxime commented 5 years ago

But what do you mean by locked ? Because, HMR is indeed not working but the app is still fully functionnal from test.

Did you make a full reload of the tab ?

cmeeren commented 5 years ago

In my repro solution you'll easily see what I mean. In the fulma demo, you can try submitting a comment, and observe that nothing happens.

MangelMaxime commented 5 years ago

Ok I wasn't testing the submit feature but navigation which was working.

Well, my fix seems to fix your issue finally. Will publish it

MangelMaxime commented 5 years ago

Should be fixed in version 3.0.2.

It has been publish but nuget needs to do it job now.

cmeeren commented 5 years ago

Thanks! Will try out.

I see that 3.0.0 was released only a handful of hours ago. I had no idea. Talk about timing!

MangelMaxime commented 5 years ago

Ok, I tested the new version in Fulma-demo and it seems to work for me.

Feel free to re-open if needed.

cmeeren commented 5 years ago

Works for me too. Thanks a lot!