diff --git a/leptos_dom/src/ssr.rs b/leptos_dom/src/ssr.rs index 36d83c7..870ee3a 100644 --- a/leptos_dom/src/ssr.rs +++ b/leptos_dom/src/ssr.rs @@ -132,7 +132,7 @@ pub fn render_to_stream_with_prefix_undisposed_with_context( let ( (shell, prefix, pending_resources, pending_fragments, serializers), scope, - _, + disposer, ) = run_scope_undisposed(runtime, { move |cx| { // Add additional context items @@ -164,31 +164,31 @@ pub fn render_to_stream_with_prefix_undisposed_with_context( // stream HTML for each as it resolves // TODO can remove id_before_suspense entirely now let fragments = fragments.map(|(fragment_id, html)| { - format!( - r#" - - - "# - ) - }); + format!( + r#" + + + "# + ) + }); // stream data for each Resource as it resolves let resources = render_serializers(serializers); @@ -196,20 +196,25 @@ pub fn render_to_stream_with_prefix_undisposed_with_context( let stream = futures::stream::once(async move { format!( r#" - {prefix} - {shell} - - "# + {prefix} + {shell} + + "# ) }) // TODO these should be combined again in a way that chains them appropriately // such that individual resources can resolve before all fragments are done .chain(fragments) - .chain(resources); + .chain(resources) + // dispose of the root scope + .chain(futures::stream::once(async move { + disposer.dispose(); + Default::default() + })); (stream, runtime, scope) } diff --git a/leptos_dom/src/ssr_in_order.rs b/leptos_dom/src/ssr_in_order.rs index af95ccf..b0a58a7 100644 --- a/leptos_dom/src/ssr_in_order.rs +++ b/leptos_dom/src/ssr_in_order.rs @@ -76,7 +76,7 @@ pub fn render_to_stream_in_order_with_prefix_undisposed_with_context( // create the runtime let runtime = create_runtime(); - let ((chunks, prefix, pending_resources, serializers), scope_id, _) = + let ((chunks, prefix, pending_resources, serializers), scope_id, disposer) = run_scope_undisposed(runtime, |cx| { // add additional context additional_context(cx); @@ -111,7 +111,12 @@ pub fn render_to_stream_in_order_with_prefix_undisposed_with_context( ) }) .chain(rx) - .chain(render_serializers(serializers)); + .chain(render_serializers(serializers)) + // dispose of the scope + .chain(futures::stream::once(async move { + disposer.dispose(); + Default::default() + })); (stream, runtime, scope_id) }