Merge branch 'master' into pr/atty303/1948

This commit is contained in:
Evan Almloff committed 2024-02-19 08:35:31 -06:00
commit c4a4a31eec
78 files changed
+1277 -4465

No files matched your search

+18 -22
View File
@@ -6,11 +6,10 @@ use dioxus_ssr::{
incremental::{IncrementalRendererConfig, RenderFreshness, WrapBody},
Renderer,
};
use serde::Serialize;
use std::future::Future;
use std::sync::Arc;
use std::sync::RwLock;
use tokio::task::{spawn_blocking, JoinHandle};
use tokio::task::JoinHandle;
use crate::prelude::*;
use dioxus_lib::prelude::*;
@@ -22,7 +21,7 @@ where
{
#[cfg(not(target_arch = "wasm32"))]
{
spawn_blocking(move || {
tokio::task::spawn_blocking(move || {
tokio::runtime::Runtime::new()
.expect("couldn't spawn runtime")
.block_on(f())
@@ -48,7 +47,6 @@ impl SsrRendererPool {
server_context: &DioxusServerContext,
) -> Result<(RenderFreshness, String), dioxus_ssr::incremental::IncrementalRendererError> {
let wrapper = FullstackRenderer {
serialized_props: None,
cfg: cfg.clone(),
server_context: server_context.clone(),
};
@@ -66,7 +64,7 @@ impl SsrRendererPool {
let prev_context = SERVER_CONTEXT.with(|ctx| ctx.replace(server_context));
// poll the future, which may call server_context()
tracing::info!("Rebuilding vdom");
let _ = vdom.rebuild(&mut NoOpMutations);
vdom.rebuild(&mut NoOpMutations);
vdom.wait_for_suspense().await;
tracing::info!("Suspense resolved");
// after polling the future, we need to restore the context
@@ -91,7 +89,11 @@ impl SsrRendererPool {
let _ = tx.send(Ok((renderer, RenderFreshness::now(None), html)));
}
Err(err) => {
dioxus_ssr::incremental::IncrementalRendererError::Other(Box::new(err));
_ = tx.send(Err(
dioxus_ssr::incremental::IncrementalRendererError::Other(Box::new(
err,
)),
));
}
}
});
@@ -122,7 +124,7 @@ impl SsrRendererPool {
.with(|ctx| ctx.replace(Box::new(server_context)));
// poll the future, which may call server_context()
tracing::info!("Rebuilding vdom");
let _ = vdom.rebuild(&mut NoOpMutations);
vdom.rebuild(&mut NoOpMutations);
vdom.wait_for_suspense().await;
tracing::info!("Suspense resolved");
// after polling the future, we need to restore the context
@@ -192,31 +194,25 @@ impl SSRState {
}
/// Render the application to HTML.
pub fn render<'a>(
pub async fn render<'a>(
&'a self,
route: String,
cfg: &'a ServeConfig,
virtual_dom_factory: impl FnOnce() -> VirtualDom + Send + Sync + 'static,
server_context: &'a DioxusServerContext,
) -> impl std::future::Future<
Output = Result<RenderResponse, dioxus_ssr::incremental::IncrementalRendererError>,
> + Send
+ 'a {
async move {
let ServeConfig { .. } = cfg;
) -> Result<RenderResponse, dioxus_ssr::incremental::IncrementalRendererError> {
let ServeConfig { .. } = cfg;
let (freshness, html) = self
.renderers
.render_to(cfg, route, virtual_dom_factory, server_context)
.await?;
let (freshness, html) = self
.renderers
.render_to(cfg, route, virtual_dom_factory, server_context)
.await?;
Ok(RenderResponse { html, freshness })
}
Ok(RenderResponse { html, freshness })
}
}
struct FullstackRenderer {
serialized_props: Option<String>,
cfg: ServeConfig,
server_context: DioxusServerContext,
}
@@ -330,7 +326,7 @@ impl RenderResponse {
fn pre_renderer() -> Renderer {
let mut renderer = Renderer::default();
renderer.pre_render = true;
renderer.into()
renderer
}
fn incremental_pre_renderer(