wip: fix ssr

This commit is contained in:
Jonathan Kelley committed 2021-12-14 22:48:20 -05:00
1 parent 2fd56e7619
commit ded9696930
7 files changed
+37 -55

No files matched your search

+7 -5
View File
@@ -5,14 +5,16 @@
//! if the type supports PartialEq. The Properties trait is used by the rsx! and html! macros to generate the type-safe builder
//! that ensures compile-time required and optional fields on cx.
use crate::innerlude::{Element, LazyNodes, Scope};
use crate::{
innerlude::{Element, Scope},
LazyNodes,
};
pub struct FragmentProps<'a>(Element<'a>);
pub struct FragmentBuilder<'a, const BUILT: bool>(Element<'a>);
impl<'a> FragmentBuilder<'a, false> {
pub fn children(self, children: Element<'a>) -> FragmentBuilder<'a, true> {
todo!()
// FragmentBuilder(children)
FragmentBuilder(children)
}
}
impl<'a, const A: bool> FragmentBuilder<'a, A> {
@@ -99,8 +101,8 @@ impl<'a> Properties for FragmentProps<'a> {
/// You want to use this free-function when your fragment needs a key and simply returning multiple nodes from rsx! won't cut it.
#[allow(non_upper_case_globals, non_snake_case)]
pub fn Fragment<'a>(cx: Scope<'a, FragmentProps<'a>>) -> Element {
todo!()
// cx.render(Some(LazyNodes::new(|f| f.fragment_from_iter(&cx.props.0))))
let i = cx.props.0.as_ref().map(|f| f.decouple());
cx.render(Some(LazyNodes::new(|f| f.fragment_from_iter(i))))
}
/// Every "Props" used for a component must implement the `Properties` trait. This trait gives some hints to Dioxus
+1 -1
View File
@@ -42,7 +42,7 @@ pub mod prelude {
pub mod exports {
//! Important dependencies that are used by the rest of the library
// the foundation of this library
//! Feel free to just add the dependencies in your own Crates.toml
pub use bumpalo;
pub use futures_channel;
}
+13
View File
@@ -774,3 +774,16 @@ impl IntoVNode<'_> for Arguments<'_> {
cx.text(self)
}
}
impl<'a> IntoVNode<'a> for &Option<VNode<'a>> {
fn into_vnode(self, cx: NodeFactory<'a>) -> VNode<'a> {
let r = self.as_ref().map(|f| f.decouple());
cx.fragment_from_iter(r)
}
}
impl<'a> IntoVNode<'a> for &VNode<'a> {
fn into_vnode(self, _cx: NodeFactory<'a>) -> VNode<'a> {
self.decouple()
}
}
+1 -30
View File
@@ -136,30 +136,7 @@ impl ScopeArena {
}
};
let mut frames = [BumpFrame::new(node_capacity), BumpFrame::new(node_capacity)];
// todo - add the node
// frames[0].nodes.get_mut().push({
// let vnode = frames[0]
// .bump
// .alloc(VNode::Text(frames[0].bump.alloc(VText {
// dom_id: Default::default(),
// is_static: false,
// text: "",
// })));
// unsafe { std::mem::transmute(vnode as *mut VNode) }
// });
// frames[1].nodes.get_mut().push({
// let vnode = frames[1]
// .bump
// .alloc(VNode::Text(frames[1].bump.alloc(VText {
// dom_id: Default::default(),
// is_static: false,
// text: "",
// })));
// unsafe { std::mem::transmute(vnode as *mut VNode) }
// });
let frames = [BumpFrame::new(node_capacity), BumpFrame::new(node_capacity)];
let scope = self.bump.alloc(ScopeState {
sender: self.sender.clone(),
@@ -217,9 +194,6 @@ impl ScopeArena {
scope.is_subtree_root.set(false);
scope.subtree.set(0);
// scope.frames[0].nodes.get_mut().clear();
// scope.frames[1].nodes.get_mut().clear();
scope.frames[0].bump.reset();
scope.frames[1].bump.reset();
@@ -258,8 +232,6 @@ impl ScopeArena {
self.nodes.borrow_mut().remove(id.0);
}
// These methods would normally exist on `scope` but they need access to *all* of the scopes
/// This method cleans up any references to data held within our hook list. This prevents mutable aliasing from
/// causing UB in our tree.
///
@@ -379,7 +351,6 @@ impl ScopeArena {
pub fn wip_head(&self, id: ScopeId) -> &VNode {
let scope = self.get_scope(id).unwrap();
let frame = scope.wip_frame();
let nodes = frame.nodes.borrow();
let node = unsafe { &*frame.nodes.get() };
unsafe { std::mem::transmute::<&VNode, &VNode>(node) }
}