1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! # Hot Reload
//!
//! Freya supports hot reloading: while your app is running, changes to your
//! code can be patched into the live process so you see updates without a
//! full rebuild and restart.
//!
//! It is powered by [`subsecond`](https://crates.io/crates/subsecond) and is
//! driven by the `dx` CLI.
//!
//! ## Installing the Dioxus CLI
//!
//! Hot reload is driven by the `dx` binary that ships with the Dioxus CLI.
//! Install it with:
//!
//! ```sh
//! cargo install dioxus-cli
//! ```
//!
//! ## Enabling Hot Reload
//!
//! Hot reload is gated behind the `hotreload` feature flag.
//! The recommended approach is to declare a feature in **your own crate** that
//! forwards to Freya's, so hot reload is never included in default or release
//! builds:
//!
//! ```toml
//! # In your Cargo.toml
//! [features]
//! hotreload = ["freya/hotreload"]
//! ```
//!
//! ## Running Your App with Hot Reload
//!
//! Use `dx serve` with the `--hot-patch` flag and your `hotreload` feature
//! enabled:
//!
//! ```sh
//! dx serve --hot-patch --features hotreload
//! ```
//!
//! `dx` will build and launch your app, then watch your sources. When you save
//! a file, it compiles a patch and pushes it into the running process; Freya
//! re-renders the UI so you can see the change immediately.
//!
//! To hot reload an example instead of the main binary, pass `--example`:
//!
//! ```sh
//! dx serve --hot-patch --features hotreload --example my_example
//! ```
//!
//! ## What Happens on Each Patch
//!
//! When a hot patch arrives, Freya:
//!
//! 1. Cancels every running task spawned with `spawn`.
//! 2. Resets every scope's hook state (`use_state`, `use_memo`, etc.).
//! 3. Marks every scope dirty and triggers a full re-render.
//!
//! In other words, hot reload re-runs your components against the patched
//! code, but **the application state stored in hooks is reset to its initial
//! values** on every patch.
//!
//! ## Limitations
//!
//! Hot reload is a development convenience, not a substitute for a rebuild.
//! Keep these caveats in mind:
//!
//! - **Hook state is reset.** Any value held by `use_state`, `use_memo`, etc.
//! goes back to its initial value on every patch.
//! - **Tasks are cancelled.** Tasks spawned with `spawn` are dropped when a
//! patch lands. Long-running background work will need to be restarted by
//! the components that own it.
//! - **Subsecond patching constraints.** Subsecond patches function bodies in
//! the running binary. Changes that alter the program's structure (adding
//! or removing functions, types, or trait impls; changing function
//! signatures; modifying struct layouts; touching `const`/`static`
//! initializers) cannot be applied as a patch. When `dx` cannot patch a
//! change, restart the app to pick it up.