fix: flickering <Transition/> in release mode (closes #960) (#1030)

This commit is contained in:
Greg Johnston 2023-05-11 14:51:33 -04:00 committed by GitHub
parent d7b919032e
commit 12ebc95800
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View file

@ -56,16 +56,17 @@ use std::rc::Rc;
tracing::instrument(level = "info", skip_all)
)]
#[component(transparent)]
pub fn Suspense<F, E>(
pub fn Suspense<F, E, V>(
cx: Scope,
/// Returns a fallback UI that will be shown while `async` [Resources](leptos_reactive::Resource) are still loading.
fallback: F,
/// Children will be displayed once all `async` [Resources](leptos_reactive::Resource) have resolved.
children: Box<dyn Fn(Scope) -> Fragment>,
children: Box<dyn Fn(Scope) -> V>,
) -> impl IntoView
where
F: Fn() -> E + 'static,
E: IntoView,
V: IntoView + 'static,
{
let context = SuspenseContext::new(cx);

View file

@ -78,7 +78,7 @@ where
F: Fn() -> E + 'static,
E: IntoView,
{
let prev_children = Rc::new(RefCell::new(None::<Vec<View>>));
let prev_children = Rc::new(RefCell::new(None::<View>));
let first_run = Rc::new(std::cell::Cell::new(true));
let child_runs = Cell::new(0);
@ -112,13 +112,13 @@ where
}
})
.children(Box::new(move |cx| {
let frag = children(cx);
let frag = children(cx).into_view(cx);
let suspense_context = use_context::<SuspenseContext>(cx)
.expect("there to be a SuspenseContext");
if cfg!(feature = "hydrate") || !first_run.get() {
*prev_children.borrow_mut() = Some(frag.nodes.clone());
*prev_children.borrow_mut() = Some(frag.clone());
}
if is_first_run(&first_run, &suspense_context) {
let has_local_only = suspense_context.has_local_only()