Minimal tracing to show order of rendering

This commit is contained in:
Greg Johnston 2022-12-15 20:56:52 -05:00
parent a253d224ac
commit fefca82d16
3 changed files with 9 additions and 6 deletions

View File

@ -107,12 +107,15 @@ where
};
if context.ready() {
leptos_dom::warn!("<Suspense/> ready");
if let Some(id) = *cached_id_borrow {
leptos_dom::warn!(" <Suspense/> continuing from {}", id);
HydrationCtx::continue_from(id);
}
child(cx).into_view(cx)
} else {
leptos_dom::warn!("<Suspense/> fallback on client");
fallback().into_view(cx)
}
})

View File

@ -11,7 +11,7 @@ pub fn App(cx: Scope) -> impl IntoView {
if cfg!(feature = "ssr") {
let (tx, rx) = futures::channel::oneshot::channel();
spawn_local(async {
std::thread::sleep(std::time::Duration::from_secs(10));
std::thread::sleep(std::time::Duration::from_secs(1));
tx.send(());
});
rx.await;
@ -22,21 +22,20 @@ pub fn App(cx: Scope) -> impl IntoView {
);
view! { cx,
<>
<div>
<div>
"This is some text"
</div>
<Suspense fallback=move || view! { cx, <p>"Loading..."</p> }>
{move || pending_thing.read().map(|n| view! { cx, <p>"Loaded."</p>})}
{move || pending_thing.read().map(|n| view! { cx, <ComponentA/> })}
</Suspense>
</>
</div>
}
}
#[component]
pub fn ComponentA(
cx: Scope,
children: Box<dyn Fn() -> Vec<View>>,
) -> impl IntoView {
let (value, set_value) = create_signal(cx, "Hello?".to_string());
let (counter, set_counter) = create_signal(cx, 0);
@ -55,7 +54,6 @@ pub fn ComponentA(
)
.child(input(cx).attr("type", "text").prop("value", value))
.child(p(cx).child("Value: ").child(value))
.child(children)
.into_view(cx)
}

View File

@ -128,6 +128,7 @@ impl ComponentRepr {
let name = name.into();
let id = HydrationCtx::id();
gloo::console::warn!("hydrating <", name.to_string(), "/> with id ", id);
let markers = (
Comment::new(Cow::Owned(format!("</{name}>")), id, true),
@ -143,6 +144,7 @@ impl ComponentRepr {
// so they can serve as our references when inserting
// future nodes
if !HydrationCtx::is_hydrating() {
gloo::console::warn!(" rendering <{name}/>");
#[cfg(debug_assertions)]
fragment
.append_with_node_2(&markers.1.node, &markers.0.node)