From 90c20ba5e37dc43a48bd5d3622b9bab75a75d46b Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Mon, 3 Jun 2024 15:55:37 -0500 Subject: [PATCH] make streaming optional --- packages/fullstack/src/render.rs | 5 ++++- packages/fullstack/src/serve_config.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/fullstack/src/render.rs b/packages/fullstack/src/render.rs index ceecbbff4a..d4b616c717 100644 --- a/packages/fullstack/src/render.rs +++ b/packages/fullstack/src/render.rs @@ -151,6 +151,7 @@ impl SsrRendererPool { server_context: server_context.clone(), }; + let stream_page = cfg.stream_page; let server_context = server_context.clone(); let mut renderer = self .renderers @@ -226,7 +227,9 @@ impl SsrRendererPool { let mut rerender = |last_render: &mut Option, virtual_dom: &VirtualDom| { if virtual_dom.suspended_tasks_remaining() { let html = renderer.render(virtual_dom); - streaming_renderer.render(html); + if stream_page { + streaming_renderer.render(html); + } *last_render = Some(Instant::now()); } }; diff --git a/packages/fullstack/src/serve_config.rs b/packages/fullstack/src/serve_config.rs index b44f1b5eb0..c109fad103 100644 --- a/packages/fullstack/src/serve_config.rs +++ b/packages/fullstack/src/serve_config.rs @@ -8,6 +8,7 @@ use std::path::PathBuf; /// A ServeConfig is used to configure how to serve a Dioxus application. It contains information about how to serve static assets, and what content to render with [`dioxus-ssr`]. #[derive(Clone, Default)] pub struct ServeConfigBuilder { + pub(crate) stream_page: bool, pub(crate) root_id: Option<&'static str>, pub(crate) index_html: Option, pub(crate) index_path: Option, @@ -19,6 +20,7 @@ impl ServeConfigBuilder { /// Create a new ServeConfigBuilder with the root component and props to render on the server. pub fn new() -> Self { Self { + stream_page: false, root_id: None, index_html: None, index_path: None, @@ -27,6 +29,13 @@ impl ServeConfigBuilder { } } + /// Set if the rendered pages should be streamed or just suspended and rendered in one large chunk. + #[allow(unused)] + pub fn stream_page(mut self, stream_page: bool) -> Self { + self.stream_page = stream_page; + self + } + /// Enable incremental static generation pub fn incremental(mut self, cfg: dioxus_ssr::incremental::IncrementalRendererConfig) -> Self { self.incremental = Some(cfg); @@ -79,6 +88,7 @@ impl ServeConfigBuilder { let index = load_index_html(index_html, root_id); ServeConfig { + stream_page: self.stream_page, index, assets_path, incremental: self.incremental, @@ -123,6 +133,7 @@ pub(crate) struct IndexHtml { /// See [`ServeConfigBuilder`] to create a ServeConfig #[derive(Clone)] pub struct ServeConfig { + pub(crate) stream_page: bool, pub(crate) index: IndexHtml, #[allow(dead_code)] pub(crate) assets_path: PathBuf,