mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 14:54:16 +00:00
Only stream Resources
if they're under a Suspense
to fix rendering issue
This commit is contained in:
parent
af68da0a9a
commit
a4747596fa
4 changed files with 38 additions and 5 deletions
|
@ -116,7 +116,7 @@ pub fn render_to_stream_with_prefix_undisposed(
|
|||
// this does NOT contain any of the data being loaded asynchronously in resources
|
||||
let shell = view(cx).render_to_string(cx);
|
||||
|
||||
let resources = cx.all_resources();
|
||||
let resources = cx.pending_resources();
|
||||
let pending_resources = serde_json::to_string(&resources).unwrap();
|
||||
let prefix = prefix(cx);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::{
|
|||
pin::Pin,
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use crate::{
|
||||
create_effect, create_isomorphic_effect, create_memo, create_signal, queue_microtask,
|
||||
runtime::{with_runtime, RuntimeId},
|
||||
|
@ -116,9 +116,23 @@ where
|
|||
suspense_contexts: Default::default(),
|
||||
});
|
||||
|
||||
let id = with_runtime(cx.runtime, |runtime| {
|
||||
runtime.create_serializable_resource(Rc::clone(&r))
|
||||
});
|
||||
cfg_if! {
|
||||
if #[cfg(any(feature = "csr", feature = "hydrate"))] {
|
||||
let id = with_runtime(cx.runtime, |runtime| {
|
||||
runtime.create_serializable_resource(Rc::clone(&r))
|
||||
});
|
||||
} else {
|
||||
let id = if use_context::<SuspenseContext>(cx).is_some() {
|
||||
with_runtime(cx.runtime, |runtime| {
|
||||
runtime.create_serializable_resource(Rc::clone(&r))
|
||||
})
|
||||
} else {
|
||||
with_runtime(cx.runtime, |runtime| {
|
||||
runtime.create_unserializable_resource(Rc::clone(&r))
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
create_isomorphic_effect(cx, {
|
||||
let r = Rc::clone(&r);
|
||||
|
|
|
@ -296,6 +296,19 @@ impl Runtime {
|
|||
.collect()
|
||||
}
|
||||
|
||||
/// Returns IDs for all [Resource]s found on any scope, pending from the server.
|
||||
pub(crate) fn pending_resources(&self) -> Vec<ResourceId> {
|
||||
self.resources
|
||||
.borrow()
|
||||
.iter()
|
||||
.filter_map(|(resource_id, res)| if matches!(res, AnyResource::Serializable(_)) {
|
||||
Some(resource_id)
|
||||
} else {
|
||||
None
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn serialization_resolvers(
|
||||
&self,
|
||||
) -> FuturesUnordered<PinnedFuture<(ResourceId, String)>> {
|
||||
|
|
|
@ -282,6 +282,12 @@ impl Scope {
|
|||
with_runtime(self.runtime, |runtime| runtime.all_resources())
|
||||
}
|
||||
|
||||
/// Returns IDs for all [Resource](crate::Resource)s found on any scope that are
|
||||
/// pending from the server.
|
||||
pub fn pending_resources(&self) -> Vec<ResourceId> {
|
||||
with_runtime(self.runtime, |runtime| runtime.pending_resources())
|
||||
}
|
||||
|
||||
/// Returns IDs for all [Resource](crate::Resource)s found on any scope.
|
||||
pub fn serialization_resolvers(&self) -> FuturesUnordered<PinnedFuture<(ResourceId, String)>> {
|
||||
with_runtime(self.runtime, |runtime| runtime.serialization_resolvers())
|
||||
|
|
Loading…
Reference in a new issue