fix dioxus ssr

This commit is contained in:
Evan Almloff committed 2024-01-10 17:57:15 -06:00
1 parent dc58212508
commit 4a1a00b0f0
27 files changed
+143 -141

No files matched your search

+31 -29
View File
@@ -2,12 +2,12 @@ use dioxus::prelude::*;
#[test]
fn root_ids() {
fn app(cx: Scope) -> Element {
fn app(_: ()) -> Element {
render! { div { width: "100px" } }
}
let mut dom = VirtualDom::new(app);
_ = dom.rebuild();
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(
dioxus_ssr::pre_render(&dom),
@@ -17,7 +17,7 @@ fn root_ids() {
#[test]
fn dynamic_attributes() {
fn app(cx: Scope) -> Element {
fn app(_: ()) -> Element {
let dynamic = 123;
render! {
div { width: "100px", div { width: "{dynamic}px" } }
@@ -25,7 +25,7 @@ fn dynamic_attributes() {
}
let mut dom = VirtualDom::new(app);
_ = dom.rebuild();
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(
dioxus_ssr::pre_render(&dom),
@@ -35,21 +35,21 @@ fn dynamic_attributes() {
#[test]
fn listeners() {
fn app(cx: Scope) -> Element {
fn app(_: ()) -> Element {
render! {
div { width: "100px", div { onclick: |_| {} } }
}
}
let mut dom = VirtualDom::new(app);
_ = dom.rebuild();
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(
dioxus_ssr::pre_render(&dom),
r#"<div style="width:100px;" data-node-hydration="0"><div data-node-hydration="1,click:1"></div></div>"#
);
fn app2(cx: Scope) -> Element {
fn app2(_: ()) -> Element {
let dynamic = 123;
render! {
div { width: "100px", div { width: "{dynamic}px", onclick: |_| {} } }
@@ -57,7 +57,7 @@ fn listeners() {
}
let mut dom = VirtualDom::new(app2);
_ = dom.rebuild();
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(
dioxus_ssr::pre_render(&dom),
@@ -67,7 +67,7 @@ fn listeners() {
#[test]
fn text_nodes() {
fn app(cx: Scope) -> Element {
fn app(_: ()) -> Element {
let dynamic_text = "hello";
render! {
div { dynamic_text }
@@ -75,14 +75,14 @@ fn text_nodes() {
}
let mut dom = VirtualDom::new(app);
_ = dom.rebuild();
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(
dioxus_ssr::pre_render(&dom),
r#"<div data-node-hydration="0"><!--node-id1-->hello<!--#--></div>"#
);
fn app2(cx: Scope) -> Element {
fn app2(_: ()) -> Element {
let dynamic = 123;
render! {
div { "{dynamic}", "{1234}" }
@@ -90,7 +90,7 @@ fn text_nodes() {
}
let mut dom = VirtualDom::new(app2);
_ = dom.rebuild();
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(
dioxus_ssr::pre_render(&dom),
@@ -101,27 +101,27 @@ fn text_nodes() {
#[allow(non_snake_case)]
#[test]
fn components_hydrate() {
fn app(cx: Scope) -> Element {
fn app(_: ()) -> Element {
render! { Child {} }
}
fn Child(cx: Scope) -> Element {
fn Child(_: ()) -> Element {
render! { div { "hello" } }
}
let mut dom = VirtualDom::new(app);
_ = dom.rebuild();
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(
dioxus_ssr::pre_render(&dom),
r#"<div data-node-hydration="0">hello</div>"#
);
fn app2(cx: Scope) -> Element {
fn app2(_: ()) -> Element {
render! { Child2 {} }
}
fn Child2(cx: Scope) -> Element {
fn Child2(_: ()) -> Element {
let dyn_text = "hello";
render! {
div { dyn_text }
@@ -129,34 +129,34 @@ fn components_hydrate() {
}
let mut dom = VirtualDom::new(app2);
_ = dom.rebuild();
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(
dioxus_ssr::pre_render(&dom),
r#"<div data-node-hydration="0"><!--node-id1-->hello<!--#--></div>"#
);
fn app3(cx: Scope) -> Element {
fn app3(_: ()) -> Element {
render! { Child3 {} }
}
fn Child3(cx: Scope) -> Element {
fn Child3(_: ()) -> Element {
render! { div { width: "{1}" } }
}
let mut dom = VirtualDom::new(app3);
_ = dom.rebuild();
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(
dioxus_ssr::pre_render(&dom),
r#"<div style="width:1;" data-node-hydration="0"></div>"#
);
fn app4(cx: Scope) -> Element {
fn app4(_: ()) -> Element {
render! { Child4 {} }
}
fn Child4(cx: Scope) -> Element {
fn Child4(_: ()) -> Element {
render! {
for _ in 0..2 {
render! {
@@ -169,7 +169,7 @@ fn components_hydrate() {
}
let mut dom = VirtualDom::new(app4);
_ = dom.rebuild();
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(
dioxus_ssr::pre_render(&dom),
@@ -179,18 +179,20 @@ fn components_hydrate() {
#[test]
fn hello_world_hydrates() {
fn app(cx: Scope) -> Element {
let mut count = use_state(cx, || 0);
use dioxus_signals::use_signal;
cx.render(rsx! {
fn app(_: ()) -> Element {
let mut count = use_signal(|| 0);
render! {
h1 { "High-Five counter: {count}" }
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
})
}
}
let mut dom = VirtualDom::new(app);
_ = dbg!(dom.rebuild());
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(
dioxus_ssr::pre_render(&dom),