2022-06-25 13:27:10 +00:00
|
|
|
use dioxus::prelude::*;
|
2022-09-13 23:22:27 +00:00
|
|
|
use dioxus_web::Config;
|
2022-01-07 05:33:09 +00:00
|
|
|
use web_sys::window;
|
|
|
|
|
2024-01-14 04:51:37 +00:00
|
|
|
fn app() -> Element {
|
2024-01-14 05:12:21 +00:00
|
|
|
rsx! {
|
2023-12-19 22:02:07 +00:00
|
|
|
div { h1 { "thing 1" } }
|
|
|
|
div { h2 { "thing 2" } }
|
2022-01-07 05:33:09 +00:00
|
|
|
div {
|
2023-12-19 22:02:07 +00:00
|
|
|
h2 { "thing 2" }
|
2022-01-07 05:33:09 +00:00
|
|
|
"asd"
|
|
|
|
"asd"
|
2022-09-13 03:01:03 +00:00
|
|
|
Bapp {}
|
2022-01-07 05:33:09 +00:00
|
|
|
}
|
2024-01-11 03:33:34 +00:00
|
|
|
{(0..10).map(|f| rsx!{
|
2022-01-07 05:33:09 +00:00
|
|
|
div {
|
|
|
|
"thing {f}"
|
|
|
|
}
|
2024-01-11 03:33:34 +00:00
|
|
|
})}
|
2024-01-14 05:12:21 +00:00
|
|
|
}
|
2022-01-07 05:33:09 +00:00
|
|
|
}
|
|
|
|
|
2022-09-30 19:03:06 +00:00
|
|
|
#[allow(non_snake_case)]
|
2024-01-14 04:51:37 +00:00
|
|
|
fn Bapp() -> Element {
|
2024-01-14 05:12:21 +00:00
|
|
|
rsx! {
|
2023-12-19 22:02:07 +00:00
|
|
|
div { h1 { "thing 1" } }
|
|
|
|
div { h2 { "thing 2" } }
|
2022-01-07 05:33:09 +00:00
|
|
|
div {
|
2023-12-19 22:02:07 +00:00
|
|
|
h2 { "thing 2" }
|
2022-01-07 05:33:09 +00:00
|
|
|
"asd"
|
|
|
|
"asd"
|
|
|
|
}
|
2024-01-14 05:12:21 +00:00
|
|
|
}
|
2022-01-07 05:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
console_error_panic_hook::set_once();
|
2023-09-12 14:07:57 +00:00
|
|
|
tracing_wasm::set_as_global_default();
|
2022-01-07 05:33:09 +00:00
|
|
|
|
|
|
|
let mut dom = VirtualDom::new(app);
|
2024-02-05 07:03:52 +00:00
|
|
|
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
2022-01-07 05:33:09 +00:00
|
|
|
|
2022-12-07 21:39:22 +00:00
|
|
|
let pre = dioxus_ssr::pre_render(&dom);
|
2023-09-06 22:47:33 +00:00
|
|
|
tracing::trace!("{}", pre);
|
2022-01-07 05:33:09 +00:00
|
|
|
|
|
|
|
// set the inner content of main to the pre-rendered content
|
|
|
|
window()
|
|
|
|
.unwrap()
|
|
|
|
.document()
|
|
|
|
.unwrap()
|
|
|
|
.get_element_by_id("main")
|
|
|
|
.unwrap()
|
|
|
|
.set_inner_html(&pre);
|
|
|
|
|
2023-12-19 22:02:07 +00:00
|
|
|
// now rehydrate
|
2024-01-19 22:19:49 +00:00
|
|
|
dioxus_web::launch::launch(app, vec![], Config::new().hydrate(true));
|
2022-01-07 05:33:09 +00:00
|
|
|
}
|