fix: <Transition/> behavior (#717)

This commit is contained in:
Greg Johnston 2023-03-21 09:05:41 -04:00 committed by GitHub
parent 982c8f6b5a
commit 2e63bb1f50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -116,9 +116,12 @@ where
let suspense_context = use_context::<SuspenseContext>(cx) let suspense_context = use_context::<SuspenseContext>(cx)
.expect("there to be a SuspenseContext"); .expect("there to be a SuspenseContext");
if is_first_run(&first_run, &suspense_context) { if cfg!(feature = "hydrate") || !first_run.get() {
let has_local_only = suspense_context.has_local_only();
*prev_children.borrow_mut() = Some(frag.nodes.clone()); *prev_children.borrow_mut() = Some(frag.nodes.clone());
}
if is_first_run(&first_run, &suspense_context) {
let has_local_only = suspense_context.has_local_only()
|| cfg!(feature = "csr");
if !has_local_only || child_runs.get() > 0 { if !has_local_only || child_runs.get() > 0 {
first_run.set(false); first_run.set(false);
} }
@ -138,17 +141,21 @@ fn is_first_run(
first_run: &Rc<Cell<bool>>, first_run: &Rc<Cell<bool>>,
suspense_context: &SuspenseContext, suspense_context: &SuspenseContext,
) -> bool { ) -> bool {
match ( if cfg!(feature = "csr") {
first_run.get(), false
cfg!(feature = "hydrate"), } else {
suspense_context.has_local_only(), match (
) { first_run.get(),
(false, _, _) => false, cfg!(feature = "hydrate"),
// is in hydrate mode, and has non-local resources (so, has streamed) suspense_context.has_local_only(),
(_, false, false) => false, ) {
// is in hydrate mode, but with only local resources (so, has not streamed) (false, _, _) => false,
(_, false, true) => true, // SSR and has non-local resources (so, has streamed)
// either SSR or client mode: it's the first run (_, false, false) => false,
(_, true, _) => true, // SSR but with only local resources (so, has not streamed)
(_, false, true) => true,
// hydrate: it's the first run
(_, true, _) => true,
}
} }
} }