fix: don't dispose of parent owners before Suspense children have been rendered

This commit is contained in:
Greg Johnston 2024-06-10 21:22:21 -04:00
parent f9eb562050
commit 095faf15b1
1 changed files with 6 additions and 4 deletions

View File

@ -6,9 +6,9 @@ use futures::FutureExt;
use leptos_macro::component;
use reactive_graph::{
computed::{suspense::SuspenseContext, ArcMemo, ScopedFuture},
owner::{provide_context, use_context},
owner::{provide_context, use_context, Owner},
signal::ArcRwSignal,
traits::{Get, Read, Track, With},
traits::{Get, Read, With},
};
use slotmap::{DefaultKey, SlotMap};
use tachys::{
@ -159,13 +159,14 @@ where
buf.next_id();
let suspense_context = use_context::<SuspenseContext>().unwrap();
let owner = Owner::current().unwrap();
let tasks = suspense_context.tasks.clone();
let (tx, rx) = futures::channel::oneshot::channel::<()>();
let mut tx = Some(tx);
let eff =
reactive_graph::effect::RenderEffect::new_isomorphic(move |_| {
tasks.track();
if tasks.read().is_empty() {
if let Some(tx) = tx.take() {
// If the receiver has dropped, it means the ScopedFuture has already
@ -196,7 +197,8 @@ where
// clean up the (now useless) effect
drop(eff);
children
OwnedView::new_with_owner(children, owner)
})));
match fut.as_mut().now_or_never() {
Some(resolved) => {