You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/perseus-macro/Cargo.toml
+6
Original file line number
Diff line number
Diff line change
@@ -32,3 +32,9 @@ trybuild = { version = "1.0", features = ["diff"] }
32
32
sycamore = "^0.7.1"
33
33
serde = { version = "1", features = [ "derive" ] }
34
34
perseus = { path = "../perseus", version = "0.3.2" }
35
+
36
+
[features]
37
+
# Enables live reloading support (which makes the macros listen for live reload events and adjust appropriately). Do NOT enable this here without also enabling it on `perseus`!
38
+
live-reload = []
39
+
# Enables support for HSR (which makes the macros respond to live reload events by freezing and thawing as appropriate). Do NOT enable this here without also enabling is on `perseus`!
# Note that this is highly experimental, and currently blocked by [rustwasm/wasm-bindgen#2735](https://github.com/rustwasm/wasm-bindgen/issues/2735)
63
63
wasm2js = []
64
64
# Enables automatic browser reloading whenever you make a change
// Instantiate an empty frozen app that can persist across templates (with interior mutability for possible thawing)
184
193
let frozen_app:Rc<RefCell<Option<(FrozenApp,ThawPrefs)>>> = Rc::new(RefCell::new(None));
185
194
195
+
// If we're using live reload, set up an indicator so that our listening to the WebSocket at the top-level (where we don't have the render context that we need for freezing/thawing)
196
+
// can signal the templates to perform freezing/thawing
197
+
// It doesn't matter what the initial value is, this is just a flip-flop
// If live reloading is enabled, connect to the server now
287
+
// This doesn't actually perform any reloading or the like, it just signals places that have access to the render context to do so (because we need that for state freezing/thawing)
/// An indicator `Signal` used to allow the root to instruct the app that we're about to reload because of an instruction from the live reloading server.
267
+
publive_reload_indicator:ReadSignal<bool>,
263
268
}
264
269
265
270
/// Fetches the information for the given page and renders it. This should be provided the actual path of the page to render (not just the
Copy file name to clipboardExpand all lines: packages/perseus/src/state/live_reload.rs
+21-18
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,10 @@
1
+
use sycamore::prelude::Signal;
1
2
use wasm_bindgen::{closure::Closure,JsCast,JsValue};
2
3
use web_sys::{ErrorEvent,MessageEvent,WebSocket};
3
4
4
-
/// Connects to the reload server if it's online.
5
-
pubfnconnect_to_reload_server(){
5
+
/// Connects to the reload server if it's online. This takes a flip-flop `Signal` that it can use to signal other parts of the code to perform actual reloading (we can't do that here because
6
+
/// we don't have access to the render context for freezing and thawing).
/// Force-reloads the page. Any code after this will NOT be called, as the browser will completely reload the page, dumping your code and restarting from the beginning. This will result in
73
+
/// a total loss of all state unless it's frozen in some way.
74
+
///
75
+
/// # Panics
76
+
/// This will panic if it was impossible to reload (which would be caused by a *very* old browser).
// We provide the translator through context, which avoids having to define a separate variable for every translation due to Sycamore's `template!` macro taking ownership with `move` closures
0 commit comments