fix: wait for blocking fragments to resolve before pulling metadata (closes #1118) (#1137)

This commit is contained in:
Greg Johnston 2023-06-02 17:32:32 -04:00 committed by GitHub
parent 2bafdf2752
commit 4e41fad107
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

@ -787,12 +787,20 @@ async fn build_stream_response(
scope: ScopeId,
) -> HttpResponse {
let cx = leptos::Scope { runtime, id: scope };
let mut stream = Box::pin(stream);
// wait for any blocking resources to load before pulling metadata
let first_app_chunk = stream.next().await.unwrap_or_default();
let (head, tail) =
html_parts_separated(options, use_context::<MetaContext>(cx).as_ref());
let mut stream = Box::pin(
futures::stream::once(async move { head.clone() })
.chain(stream)
.chain(
futures::stream::once(async move { first_app_chunk })
.chain(stream),
)
.chain(futures::stream::once(async move {
runtime.dispose();
tail.to_string()

View file

@ -685,11 +685,14 @@ async fn forward_stream(
mut tx: Sender<String>,
) {
let cx = Scope { runtime, id: scope };
let mut shell = Box::pin(bundle);
let first_app_chunk = shell.next().await.unwrap_or_default();
let (head, tail) =
html_parts_separated(options, use_context::<MetaContext>(cx).as_ref());
_ = tx.send(head).await;
let mut shell = Box::pin(bundle);
_ = tx.send(first_app_chunk).await;
while let Some(fragment) = shell.next().await {
_ = tx.send(fragment).await;
}