Skip to content

Commit

Permalink
fix ssg
Browse files Browse the repository at this point in the history
  • Loading branch information
ealmloff committed Jun 3, 2024
1 parent 36e9f87 commit 64987fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/fullstack/src/axum_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub async fn render_handler_with_context<F: FnMut(&mut DioxusServerContext)>(
let url = parts.uri.path_and_query().unwrap().to_string();
let parts: Arc<parking_lot::RwLock<http::request::Parts>> =
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
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions packages/fullstack/src/server_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,21 @@ mod server_fn_impl {

impl DioxusServerContext {
/// Create a new server context from a request
pub fn new(parts: impl Into<Arc<parking_lot::RwLock<http::request::Parts>>>) -> 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<RwLock<http::request::Parts>>) -> 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,
Expand Down
2 changes: 1 addition & 1 deletion packages/static-generation/src/ssg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 64987fe

Please sign in to comment.