mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 14:54:16 +00:00
Work on hydration
This commit is contained in:
parent
2e11e2037f
commit
4008240bff
3 changed files with 36 additions and 29 deletions
|
@ -132,12 +132,12 @@ pub fn insert(
|
|||
"inserting {value:?} on {} before {before:?} with initial = {initial:?}",
|
||||
parent.node_name()
|
||||
); */
|
||||
let initial =
|
||||
if before != Marker::NoChildren && (initial == None || initial == Some(Child::Null)) {
|
||||
Some(Child::Nodes(vec![]))
|
||||
} else {
|
||||
initial
|
||||
};
|
||||
/* let initial =
|
||||
if before != Marker::NoChildren && (initial == None || initial == Some(Child::Null)) {
|
||||
Some(Child::Nodes(vec![]))
|
||||
} else {
|
||||
initial
|
||||
}; */
|
||||
|
||||
match value {
|
||||
Child::Fn(f) => {
|
||||
|
@ -184,10 +184,10 @@ pub fn insert_expression(
|
|||
mut current: Child,
|
||||
before: &Marker,
|
||||
) -> Child {
|
||||
#[cfg(feature = "hydrate")]
|
||||
/* #[cfg(feature = "hydrate")]
|
||||
if cx.is_hydrating() && current == Child::Null {
|
||||
current = Child::Nodes(child_nodes(&parent));
|
||||
}
|
||||
} */
|
||||
|
||||
log::debug!("insert_expression\nparent = {}\nnew_value = {new_value:?}\ncurrent = {current:?}\nbefore = {before:?}", parent.node_name());
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ fn root_element_to_tokens(template_uid: &Ident, node: &Node, mode: Mode) -> Toke
|
|||
// for hydration, use get_next_element(), which will either draw from an SSRed node or clone the template
|
||||
Mode::Hydrate => quote! {
|
||||
let root = #template_uid.with(|template| cx.get_next_element(template));
|
||||
log::debug!("root node = {:#?}", root.outer_html());
|
||||
//log::debug!("root node = {:#?}", root.outer_html());
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -596,6 +596,20 @@ fn child_to_tokens(
|
|||
Mode::Client => {
|
||||
template.push_str("<!>");
|
||||
navigations.push(location);
|
||||
|
||||
let current = match current {
|
||||
Some(i) => quote! { Some(#i.into_child(cx)) },
|
||||
None => quote! { None },
|
||||
};
|
||||
expressions.push(quote! {
|
||||
leptos::insert(
|
||||
cx,
|
||||
#parent.clone(),
|
||||
#value.into_child(cx),
|
||||
#before,
|
||||
#current,
|
||||
);
|
||||
});
|
||||
}
|
||||
// when hydrating, a text node will be generated by SSR; in the hydration/CSR template,
|
||||
// wrap it with comments that mark where it begins and ends
|
||||
|
@ -610,7 +624,16 @@ fn child_to_tokens(
|
|||
navigations.push(quote! {
|
||||
#location;
|
||||
let (#el, #co) = cx.get_next_marker(&#parent);
|
||||
log::debug!("get_next_marker => {} [{:?}]", #el.node_name(), #co.iter().map(|c| c.node_name()).collect::<Vec<_>>());
|
||||
});
|
||||
|
||||
expressions.push(quote! {
|
||||
leptos::insert(
|
||||
cx,
|
||||
#el.clone(),
|
||||
#value.into_child(cx),
|
||||
Marker::NoChildren,
|
||||
Some(Child::Nodes(#co)),
|
||||
);
|
||||
});
|
||||
|
||||
current = Some(co);
|
||||
|
@ -623,22 +646,6 @@ fn child_to_tokens(
|
|||
}),
|
||||
}
|
||||
|
||||
if mode != Mode::Ssr {
|
||||
let current = match current {
|
||||
Some(i) => quote! { Some(#i.into_child(cx)) },
|
||||
None => quote! { None },
|
||||
};
|
||||
expressions.push(quote! {
|
||||
leptos::insert(
|
||||
cx,
|
||||
#parent.clone(),
|
||||
#value.into_child(cx),
|
||||
#before,
|
||||
#current,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
PrevSibChange::Sib(name)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,8 +100,8 @@ impl SharedContext {
|
|||
completed: Default::default(),
|
||||
events: Default::default(),
|
||||
context: Some(HydrationContext {
|
||||
id: "".into(),
|
||||
count: -1,
|
||||
id: "0-".into(),
|
||||
count: 0,
|
||||
}),
|
||||
registry,
|
||||
pending_resources,
|
||||
|
@ -117,7 +117,7 @@ impl SharedContext {
|
|||
} else {
|
||||
self.context = Some(HydrationContext {
|
||||
id: "0-".into(),
|
||||
count: 0,
|
||||
count: 1,
|
||||
});
|
||||
"0-0".into()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue