@@ -4,6 +4,7 @@ use crate::serve::PageDataWithHead;
4
4
use crate :: template:: Template ;
5
5
use crate :: ClientTranslationsManager ;
6
6
use crate :: ErrorPages ;
7
+ use js_sys:: Reflect ;
7
8
use std:: cell:: RefCell ;
8
9
use std:: collections:: HashMap ;
9
10
use std:: rc:: Rc ;
@@ -125,12 +126,6 @@ pub enum InitialState {
125
126
NotPresent ,
126
127
}
127
128
128
- // We have to rely on JS to set a global variable unfortunately (should file an error on `web_sys` about this)
129
- #[ wasm_bindgen( module = "/src/unset_initial_state.js" ) ]
130
- extern "C" {
131
- fn unset_initial_state ( ) ;
132
- }
133
-
134
129
/// 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
135
130
/// broader template). Asynchronous Wasm is handled here, because only a few cases need it.
136
131
// TODO handle exceptions higher up
@@ -150,7 +145,13 @@ pub async fn app_shell(
150
145
// The state is here, and the HTML has already been injected for us (including head metadata)
151
146
InitialState :: Present ( state) => {
152
147
// Unset the initial state variable so we perform subsequent renders correctly
153
- unset_initial_state ( ) ;
148
+ // This monstrosity is needed until `web-sys` adds a `.set()` method on `Window`
149
+ Reflect :: set (
150
+ & JsValue :: from ( web_sys:: window ( ) . unwrap ( ) ) ,
151
+ & JsValue :: from ( "__PERSEUS_INITIAL_STATE" ) ,
152
+ & JsValue :: undefined ( ) ,
153
+ )
154
+ . unwrap ( ) ;
154
155
// We need to move the server-rendered content from its current container to the reactive container (otherwise Sycamore can't work with it properly)
155
156
let initial_html = initial_container. inner_html ( ) ;
156
157
container_rx_elem. set_inner_html ( & initial_html) ;
0 commit comments