diff --git a/packages/fullstack/src/axum_adapter.rs b/packages/fullstack/src/axum_adapter.rs index 33698c4a71..160320eb69 100644 --- a/packages/fullstack/src/axum_adapter.rs +++ b/packages/fullstack/src/axum_adapter.rs @@ -342,7 +342,7 @@ pub async fn render_handler_with_context( let url = parts.uri.path_and_query().unwrap().to_string(); let parts: Arc> = Arc::new(parking_lot::RwLock::new(parts)); - let mut server_context = DioxusServerContext::new(parts.clone()); + let mut server_context = DioxusServerContext::from_shared_parts(parts.clone()); inject_context(&mut server_context); match ssr_state @@ -405,7 +405,7 @@ async fn handle_server_fns_inner( if let Some(mut service) = server_fn::axum::get_server_fn_service(&path_string) { - let server_context = DioxusServerContext::new(Arc::new(parking_lot::RwLock::new(parts))); + let server_context = DioxusServerContext::new(parts); additional_context(); // store Accepts and Referrer in case we need them for redirect (below) diff --git a/packages/fullstack/src/server_context.rs b/packages/fullstack/src/server_context.rs index 802a72eb8f..d45e98a0db 100644 --- a/packages/fullstack/src/server_context.rs +++ b/packages/fullstack/src/server_context.rs @@ -39,9 +39,21 @@ mod server_fn_impl { impl DioxusServerContext { /// Create a new server context from a request - pub fn new(parts: impl Into>>) -> Self { + pub fn new(parts: http::request::Parts) -> Self { Self { - parts: parts.into(), + parts: Arc::new(RwLock::new(parts)), + shared_context: Arc::new(RwLock::new(SendSyncAnyMap::new())), + response_parts: std::sync::Arc::new(RwLock::new( + http::response::Response::new(()).into_parts().0, + )), + html_data: Arc::new(RwLock::new(HTMLData::default())), + } + } + + /// Create a server context from a shared parts + pub(crate) fn from_shared_parts(parts: Arc>) -> Self { + Self { + parts, shared_context: Arc::new(RwLock::new(SendSyncAnyMap::new())), response_parts: std::sync::Arc::new(RwLock::new( http::response::Response::new(()).into_parts().0, diff --git a/packages/static-generation/src/ssg.rs b/packages/static-generation/src/ssg.rs index de9703e059..f401a95677 100644 --- a/packages/static-generation/src/ssg.rs +++ b/packages/static-generation/src/ssg.rs @@ -13,7 +13,7 @@ fn server_context_for_route(route: &str) -> dioxus_fullstack::prelude::DioxusSer let request = http::Request::builder().uri(route).body(()).unwrap(); let (parts, _) = request.into_parts(); - DioxusServerContext::new(Arc::new(tokio::sync::RwLock::new(parts))) + DioxusServerContext::new(parts) } /// Try to extract the site map by finding the root router that a component renders.