wip: stop transmuting reference

This commit is contained in:
Jonathan Kelley committed 2022-11-21 17:00:34 -08:00
1 parent d407035931
commit 491bf4332d
8 files changed
+263 -244

No files matched your search

+50 -45
View File
@@ -1,5 +1,5 @@
use super::cache::Segment;
use dioxus_core::{prelude::*, AttributeValue, DynamicNode};
use dioxus_core::{prelude::*, AttributeValue, DynamicNode, VText};
use std::collections::HashMap;
use std::fmt::Write;
use std::rc::Rc;
@@ -18,7 +18,7 @@ impl SsrRender {
let root = scope.root_node();
let mut out = String::new();
self.render_template(&mut out, dom, root).unwrap();
// self.render_template(&mut out, dom, root).unwrap();
out
}
@@ -46,32 +46,37 @@ impl SsrRender {
};
}
Segment::Node(idx) => match &template.dynamic_nodes[*idx] {
DynamicNode::Text { value, inner, .. } => {
// in SSR, we are concerned that we can't hunt down the right text node since they might get merged
if !*inner {
write!(buf, "<!--#-->")?;
}
DynamicNode::Component(_) => todo!(),
DynamicNode::Text(_) => todo!(),
DynamicNode::Fragment(_) => todo!(),
DynamicNode::Placeholder(_) => todo!(),
// todo!()
// DynamicNode::Text(VText { id, value }) => {
// // in SSR, we are concerned that we can't hunt down the right text node since they might get merged
// // if !*inner {
// write!(buf, "<!--#-->")?;
// // }
// todo: escape the text
write!(buf, "{}", value)?;
// // todo: escape the text
// write!(buf, "{}", value)?;
if !*inner {
write!(buf, "<!--/#-->")?;
}
}
DynamicNode::Fragment { nodes, .. } => {
for child in *nodes {
self.render_template(buf, dom, child)?;
}
}
DynamicNode::Component { scope, .. } => {
let id = scope.get().unwrap();
let scope = dom.get_scope(id).unwrap();
self.render_template(buf, dom, scope.root_node())?;
}
DynamicNode::Placeholder(_el) => {
write!(buf, "<!--placeholder-->")?;
}
// // if !*inner {
// write!(buf, "<!--/#-->")?;
// // }
// }
// DynamicNode::Fragment { nodes, .. } => {
// for child in *nodes {
// self.render_template(buf, dom, child)?;
// }
// }
// DynamicNode::Component { scope, .. } => {
// let id = scope.get().unwrap();
// let scope = dom.get_scope(id).unwrap();
// self.render_template(buf, dom, scope.root_node())?;
// }
// DynamicNode::Placeholder(_el) => {
// write!(buf, "<!--placeholder-->")?;
// }
},
Segment::PreRendered(contents) => buf.push_str(contents),
@@ -107,24 +112,24 @@ fn to_string_works() {
use Segment::*;
assert_eq!(
StringCache::from_template(&dom.base_scope().root_node())
.unwrap()
.segments,
vec![
PreRendered("<div class=\"asdasdasd\" class=\"asdasdasd\"".into(),),
Attr(0,),
PreRendered(">Hello world 1 -->".into(),),
Node(0,),
PreRendered("<-- Hello world 2<div>nest 1</div><div></div><div>nest 2</div>".into(),),
Node(1,),
Node(2,),
PreRendered("</div>".into(),),
]
);
// assert_eq!(
// StringCache::from_template(&dom.base_scope().root_node())
// .unwrap()
// .segments,
// vec![
// PreRendered("<div class=\"asdasdasd\" class=\"asdasdasd\"".into(),),
// Attr(0,),
// PreRendered(">Hello world 1 -->".into(),),
// Node(0,),
// PreRendered("<-- Hello world 2<div>nest 1</div><div></div><div>nest 2</div>".into(),),
// Node(1,),
// Node(2,),
// PreRendered("</div>".into(),),
// ]
// );
assert_eq!(
SsrRender::default().render_vdom(&dom),
"<div class=\"asdasdasd\" class=\"asdasdasd\" id=\"id-123\">Hello world 1 --><!--#-->123<!--/#--><-- Hello world 2<div>nest 1</div><div></div><div>nest 2</div><!--#--></diiiiiiiiv><!--/#--><div><!--#-->finalize 0<!--/#--></div><div><!--#-->finalize 1<!--/#--></div><div><!--#-->finalize 2<!--/#--></div><div><!--#-->finalize 3<!--/#--></div><div><!--#-->finalize 4<!--/#--></div></div>"
);
// assert_eq!(
// SsrRender::default().render_vdom(&dom),
// "<div class=\"asdasdasd\" class=\"asdasdasd\" id=\"id-123\">Hello world 1 --><!--#-->123<!--/#--><-- Hello world 2<div>nest 1</div><div></div><div>nest 2</div><!--#--></diiiiiiiiv><!--/#--><div><!--#-->finalize 0<!--/#--></div><div><!--#-->finalize 1<!--/#--></div><div><!--#-->finalize 2<!--/#--></div><div><!--#-->finalize 3<!--/#--></div><div><!--#-->finalize 4<!--/#--></div></div>"
// );
}