Skip to content

Commit dc21490

Browse files
committed
refactor(routing): ♻️ refactored to eliminate only remaining js
Perseus is officially 100% pure Rust!
1 parent f84cfb0 commit dc21490

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

packages/perseus/src/shell.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::serve::PageDataWithHead;
44
use crate::template::Template;
55
use crate::ClientTranslationsManager;
66
use crate::ErrorPages;
7+
use js_sys::Reflect;
78
use std::cell::RefCell;
89
use std::collections::HashMap;
910
use std::rc::Rc;
@@ -125,12 +126,6 @@ pub enum InitialState {
125126
NotPresent,
126127
}
127128

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-
134129
/// 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
135130
/// broader template). Asynchronous Wasm is handled here, because only a few cases need it.
136131
// TODO handle exceptions higher up
@@ -150,7 +145,13 @@ pub async fn app_shell(
150145
// The state is here, and the HTML has already been injected for us (including head metadata)
151146
InitialState::Present(state) => {
152147
// 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();
154155
// We need to move the server-rendered content from its current container to the reactive container (otherwise Sycamore can't work with it properly)
155156
let initial_html = initial_container.inner_html();
156157
container_rx_elem.set_inner_html(&initial_html);

packages/perseus/src/unset_initial_state.js

-4
This file was deleted.

0 commit comments

Comments
 (0)