fixed `DynChild` panicking when expected text is not there

This commit is contained in:
Jose Quesada 2022-12-23 07:54:29 -06:00
parent d158c34d24
commit a5d7563a67
2 changed files with 18 additions and 21 deletions

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(1));
std::thread::sleep(std::time::Duration::from_millis(10));
tx.send(());
});
rx.await;
@ -26,17 +26,15 @@ pub fn App(cx: Scope) -> impl IntoView {
<div>
"This is some text"
</div>
<Suspense fallback=move || view! { cx, <p>"Loading..."</p> }>
// <Suspense fallback=move || view! { cx, <p>"Loading..."</p> }>
{move || pending_thing.read().map(|n| view! { cx, <ComponentA/> })}
</Suspense>
// </Suspense>
</div>
}
}
#[component]
pub fn ComponentA(
cx: Scope,
) -> impl IntoView {
pub fn ComponentA(cx: Scope) -> impl IntoView {
let (value, set_value) = create_signal(cx, "Hello?".to_string());
let (counter, set_counter) = create_signal(cx, 0);

View File

@ -1,5 +1,5 @@
use cfg_if::cfg_if;
use crate::{hydration::HydrationCtx, Comment, IntoView, View};
use cfg_if::cfg_if;
use leptos_reactive::Scope;
use std::{borrow::Cow, cell::RefCell, fmt, ops::Deref, rc::Rc};
cfg_if! {
@ -233,23 +233,22 @@ where
else {
// We need to remove the text created from SSR
if HydrationCtx::is_hydrating() && new_child.get_text().is_some() {
let t = closing
.previous_sibling()
.unwrap()
.unchecked_into::<web_sys::Element>();
if let Some(t) = closing.previous_sibling() {
let t = t.unchecked_into::<web_sys::Element>();
// See note on ssr.rs when matching on `DynChild`
// for more details on why we need to do this for
// release
if !cfg!(debug_assertions) {
t.previous_sibling()
.unwrap()
.unchecked_into::<web_sys::Element>()
.remove();
// See note on ssr.rs when matching on `DynChild`
// for more details on why we need to do this for
// release
if !cfg!(debug_assertions) {
t.previous_sibling()
.unwrap()
.unchecked_into::<web_sys::Element>()
.remove();
}
t.remove();
}
t.remove();
mount_child(MountKind::Before(&closing), &new_child);
}