Skip to content

1.1.2

Compare
Choose a tag to compare
@lydell lydell released this 17 Jan 20:50
· 29 commits to main since this release

Improved: When a new port is added after hot reloading, elm-watch used to log a message to the console using console.info(), saying that you might want to reload the page. What I’ve learned from using elm-watch in real projects though, is that I’d rather want elm-watch to just reload the page for me in that case (like it does in some other cases), to give JavaScript code a chance to set those ports up.

Here’s a use case for reloading:

  1. Start elm-watch, but don’t open any tabs in the browser, so no target is connected via WebSocket to elm-watch.
  2. Add a new port in Elm. elm-watch just typechecks the code, but does not compile it to JS.
  3. Use that port in JavaScript.
  4. Go to the app in the browser.

State: The JavaScript is ready for the new port already, but the compiled JS for Elm is old.

What happens: elm-watch starts compiling for real since the target connected via WebSocket, and sends over the new JS. We detect the new port and reload the page. The JavaScript code now gets to set that port up for real.

This is especially helpful if your JavaScript code results in some kind of error when it expects certain ports but those not being available from Elm at page load (since elm-watch compiles lazily until first opened in the browser). I used to be confused why there were errors. Now, the page is automatically reloaded and the errors go away by themselves.