miso
Copyright(C) 2016-2026 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Reload

Contents

Description

Overview

Miso.Reload supports hot-reloading of miso applications during interactive development with GHC WASM browser mode (ghciwatch + WASM GHCi). It provides two entry points that replace startApp in your main:

reload
clears <head> and <body> — full reset on every :r; model is lost
live
clears <body> only — model state survives :r

reload

Clears both <head> and <body>, kills any running scheduler thread, and re-mounts the component from scratch. All application state is lost. Use this when you are actively changing the model type.

main :: IO ()
main = reload defaultEvents app

live

Clears only <body>, then re-mounts the component using the __old model__ value recovered from the previous GHCi session via a C-heap stable pointer. <head> injections (stylesheets, scripts) from the previous session are preserved.

main :: IO ()
main = live defaultEvents app

Warning: live is unsafe if you change the model type between reloads (adding, removing, or changing a field's type). Such a change will produce a segfault because the old in-memory model is coerced directly into the new type. Use reload whenever you alter the model schema.

See also

Synopsis

Functions

reload Source #

Arguments

:: Eq model 
=> Events

Event delegation map (typically defaultEvents)

-> App model action

Top-level application component to (re-)mount

-> IO () 

Clears the <body> and <head> on each reload.

Meant to be used with WASM browser mode.

main :: IO ()
main = reload defaultEvents app

N.B. This also resets the internal component state. This means all currently mounted components become unmounted and ComponentId are reset to their original form factory.

If you'd like to preserve application state between calls to GHCi `:r`, see live.

Since: 1.9.0.0

live Source #

Arguments

:: Eq model 
=> Events

Event delegation map (typically defaultEvents)

-> App model action

Top-level application component to (re-)mount with preserved model state

-> IO () 

Live reloading. Persists all Component model between successive GHCi reloads.

This means application state should persist between GHCi reloads

Schema changes to model are currently unsupported. If you're changing fields in model (adding, removing, changing a field's type), this will more than likely segfault. If you change the view or update functions it will be fine.

Use reload if you're changing the model frequently and live if you're adjusting the view / update function logic.

main :: IO ()
main = live defaultEvents app

Since: 1.9.0.0