mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
fix: implement dry_resolve
on Suspend so that resources created inside a Suspend are registered (closes #2917) (#2940)
This commit is contained in:
parent
f3c57f8bce
commit
32bea69c28
2 changed files with 20 additions and 36 deletions
|
@ -21,7 +21,6 @@ slotmap = { version = "1.0", optional = true }
|
||||||
oco_ref = { workspace = true, optional = true }
|
oco_ref = { workspace = true, optional = true }
|
||||||
once_cell = "1.19"
|
once_cell = "1.19"
|
||||||
paste = "1.0"
|
paste = "1.0"
|
||||||
pin-project-lite = "0.2.14"
|
|
||||||
wasm-bindgen = "0.2.93"
|
wasm-bindgen = "0.2.93"
|
||||||
html-escape = "0.2.13"
|
html-escape = "0.2.13"
|
||||||
js-sys = "0.3.69"
|
js-sys = "0.3.69"
|
||||||
|
|
|
@ -10,7 +10,6 @@ use crate::{
|
||||||
};
|
};
|
||||||
use any_spawner::Executor;
|
use any_spawner::Executor;
|
||||||
use futures::{select, FutureExt};
|
use futures::{select, FutureExt};
|
||||||
use pin_project_lite::pin_project;
|
|
||||||
use reactive_graph::{
|
use reactive_graph::{
|
||||||
computed::{
|
computed::{
|
||||||
suspense::{LocalResourceNotifier, SuspenseContext},
|
suspense::{LocalResourceNotifier, SuspenseContext},
|
||||||
|
@ -27,20 +26,17 @@ use std::{
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
pin_project! {
|
/// A suspended `Future`, which can be used in the view.
|
||||||
/// A suspended `Future`, which can be used in the view.
|
#[derive(Clone)]
|
||||||
#[derive(Clone)]
|
pub struct Suspend<Fut> {
|
||||||
pub struct Suspend<Fut> {
|
inner: Pin<Box<ScopedFuture<Fut>>>,
|
||||||
#[pin]
|
|
||||||
inner: ScopedFuture<Fut>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Fut> Suspend<Fut> {
|
impl<Fut> Suspend<Fut> {
|
||||||
/// Creates a new suspended view.
|
/// Creates a new suspended view.
|
||||||
pub fn new(fut: Fut) -> Self {
|
pub fn new(fut: Fut) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: ScopedFuture::new(fut),
|
inner: Box::pin(ScopedFuture::new(fut)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,21 +47,19 @@ where
|
||||||
{
|
{
|
||||||
type Output = Fut::Output;
|
type Output = Fut::Output;
|
||||||
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(
|
||||||
let this = self.project();
|
mut self: Pin<&mut Self>,
|
||||||
this.inner.poll(cx)
|
cx: &mut Context<'_>,
|
||||||
|
) -> Poll<Self::Output> {
|
||||||
|
self.inner.as_mut().poll(cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Fut> From<ScopedFuture<Fut>> for Suspend<Fut> {
|
impl<Fut> From<ScopedFuture<Fut>> for Suspend<Fut> {
|
||||||
fn from(inner: ScopedFuture<Fut>) -> Self {
|
fn from(inner: ScopedFuture<Fut>) -> Self {
|
||||||
Self { inner }
|
Self {
|
||||||
}
|
inner: Box::pin(inner),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Fut> From<Suspend<Fut>> for ScopedFuture<Fut> {
|
|
||||||
fn from(value: Suspend<Fut>) -> Self {
|
|
||||||
value.inner
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,21 +181,10 @@ where
|
||||||
Self::Output<NewAttr>: RenderHtml<Rndr>,
|
Self::Output<NewAttr>: RenderHtml<Rndr>,
|
||||||
{
|
{
|
||||||
let attr = attr.into_cloneable_owned();
|
let attr = attr.into_cloneable_owned();
|
||||||
let ScopedFuture {
|
Suspend::new(Box::pin(async move {
|
||||||
owner,
|
let this = self.inner.await;
|
||||||
observer,
|
this.add_any_attr(attr)
|
||||||
fut,
|
}))
|
||||||
} = self.into();
|
|
||||||
Suspend::from(ScopedFuture {
|
|
||||||
owner,
|
|
||||||
observer,
|
|
||||||
fut: Box::pin(async move {
|
|
||||||
let this = fut.await;
|
|
||||||
this.add_any_attr(attr)
|
|
||||||
}) as Pin<Box<dyn Future<
|
|
||||||
Output = <<Fut as Future>::Output as AddAnyAttr<Rndr>>::Output<<NewAttr as Attribute<Rndr>>::CloneableOwned>> + Send + 'static
|
|
||||||
>>
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,5 +321,7 @@ where
|
||||||
Some(self.await)
|
Some(self.await)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dry_resolve(&mut self) {}
|
fn dry_resolve(&mut self) {
|
||||||
|
self.inner.as_mut().now_or_never();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue