Skip to content

Commit

Permalink
make streaming optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ealmloff committed Jun 3, 2024
1 parent 64987fe commit 90c20ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/fullstack/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -226,7 +227,9 @@ impl SsrRendererPool {
let mut rerender = |last_render: &mut Option<Instant>, 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());
}
};
Expand Down
11 changes: 11 additions & 0 deletions packages/fullstack/src/serve_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub(crate) index_path: Option<PathBuf>,
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 90c20ba

Please sign in to comment.