Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fullstack history #1987

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/fullstack/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use dioxus_ssr::{
use std::future::Future;
use std::sync::Arc;
use std::sync::RwLock;
use tokio::task::block_in_place;
use tokio::task::JoinHandle;

use crate::prelude::*;
Expand Down Expand Up @@ -64,7 +65,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");
vdom.rebuild(&mut NoOpMutations);
block_in_place(|| vdom.rebuild(&mut NoOpMutations));
vdom.wait_for_suspense().await;
tracing::info!("Suspense resolved");
// after polling the future, we need to restore the context
Expand Down Expand Up @@ -124,7 +125,7 @@ impl SsrRendererPool {
.with(|ctx| ctx.replace(Box::new(server_context)));
// poll the future, which may call server_context()
tracing::info!("Rebuilding vdom");
vdom.rebuild(&mut NoOpMutations);
block_in_place(|| vdom.rebuild(&mut NoOpMutations));
vdom.wait_for_suspense().await;
tracing::info!("Suspense resolved");
// after polling the future, we need to restore the context
Expand Down
28 changes: 25 additions & 3 deletions packages/fullstack/src/server_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,36 @@ mod server_fn_impl {
/// Get the request that triggered:
/// - The initial SSR render if called from a ScopeState or ServerFn
/// - The server function to be called if called from a server function after the initial render
pub fn request_parts(&self) -> tokio::sync::RwLockReadGuard<'_, http::request::Parts> {
pub async fn request_parts(
&self,
) -> tokio::sync::RwLockReadGuard<'_, http::request::Parts> {
self.parts.read().await
}

/// Get the request that triggered:
/// - The initial SSR render if called from a ScopeState or ServerFn
/// - The server function to be called if called from a server function after the initial render
pub fn request_parts_blocking(
&self,
) -> tokio::sync::RwLockReadGuard<'_, http::request::Parts> {
self.parts.blocking_read()
}

/// Get the request that triggered:
/// - The initial SSR render if called from a ScopeState or ServerFn
/// - The server function to be called if called from a server function after the initial render
pub fn request_parts_mut(&self) -> tokio::sync::RwLockWriteGuard<'_, http::request::Parts> {
pub async fn request_parts_mut(
&self,
) -> tokio::sync::RwLockWriteGuard<'_, http::request::Parts> {
self.parts.write().await
}

/// Get the request that triggered:
/// - The initial SSR render if called from a ScopeState or ServerFn
/// - The server function to be called if called from a server function after the initial render
pub fn request_parts_mut_blocking(
&self,
) -> tokio::sync::RwLockWriteGuard<'_, http::request::Parts> {
self.parts.blocking_write()
}

Expand Down Expand Up @@ -239,6 +261,6 @@ impl<
type Rejection = R;

async fn from_request(req: &DioxusServerContext) -> Result<Self, Self::Rejection> {
Ok(I::from_request_parts(&mut req.request_parts_mut(), &()).await?)
Ok(I::from_request_parts(&mut *req.request_parts_mut().await, &()).await?)
}
}
2 changes: 1 addition & 1 deletion packages/router/src/router_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ where
return Box::new(AnyHistoryProviderImplWrapper::new(
MemoryHistory::<R>::with_initial_path(
dioxus_fullstack::prelude::server_context()
.request_parts()
.request_parts_blocking()
.uri
.to_string()
.parse()
Expand Down
Loading