Hot reload in miso uses the WASM backend only. The GHCJS (JavaScript) backend does not support GHCi browser mode.
Requirements
- GHC WASM backend — acquired via
nix develop .#wasmfrom miso’s flake (see Nix) - ghciwatch — included in the WASM dev shell
- miso-sampler — the template repository with ready-made build scripts
Setup
Clone the miso-sampler template
miso-sampler is the official template repository. It includes a Makefile with build targets for WASM, GHCJS, and GHC.Enter the WASM dev shell
ghciwatch, bun, http-server, and cabal-install.Start hot reload
The WASM shell exposes a This runs:
repl-watch function:ghciwatch watches all files in the current directory. When a Haskell source file changes, it reloads GHCi and calls :main, which re-runs the miso application in the browser.How it works
The GHC WASM backend includes a special GHCi mode (-fghci-browser) that compiles Haskell to WASM and executes it directly inside a browser tab over a WebSocket connection. Instead of a full compile-link-bundle cycle, GHCi loads only changed modules.
ghciwatch coordinates the outer loop:
- Watches the filesystem for changes
- Sends a reload command to the running GHCi session
- Runs
:mainafter each successful reload
--debounce 50ms flag prevents rapid successive saves from triggering multiple reloads.
Shell functions
The WASM dev shell defines several convenience functions:Production builds
Hot reload is a development-only workflow. For production, build the full WASM bundle:Miso.Reload functions
TheMiso.Reload module exports two functions for use with WASM browser mode:
| Use | When |
|---|---|
live | Iterating on view or update logic, model schema is stable |
reload | Changing model type (adding/removing/changing fields) |
live by default:
INTERACTIVE CPP flag is set during hot reload builds.
Further reading
- WASM GHCi browser mode — Tweag blog post explaining the underlying technology
- miso-sampler README — browser mode section with step-by-step instructions
- ghciwatch — the file watcher used to drive reload