Browse Source

fix cargo check all features except the router

Evan Almloff 1 year ago
parent
commit
14b4af4bbc

+ 1 - 1
packages/fullstack/examples/axum-desktop/Cargo.toml

@@ -7,7 +7,7 @@ publish = false
 [lib]
 [lib]
 
 
 [dependencies]
 [dependencies]
-dioxus = { workspace = true, features = ["launch"] }
+dioxus = { workspace = true, features = ["launch", "fullstack"] }
 axum = { workspace = true, optional = true }
 axum = { workspace = true, optional = true }
 tokio = { workspace = true, features = ["full"], optional = true }
 tokio = { workspace = true, features = ["full"], optional = true }
 serde = "1.0.159"
 serde = "1.0.159"

+ 1 - 1
packages/fullstack/examples/axum-desktop/src/server.rs

@@ -5,7 +5,7 @@
 
 
 use axum_desktop::*;
 use axum_desktop::*;
 use dioxus::prelude::*;
 use dioxus::prelude::*;
-use dioxus_fullstack::server_fn::axum::register_explicit;
+use server_fn::axum::register_explicit;
 
 
 #[tokio::main]
 #[tokio::main]
 async fn main() {
 async fn main() {

+ 19 - 10
packages/fullstack/examples/static-hydrated/src/main.rs

@@ -14,16 +14,25 @@ use serde::{Deserialize, Serialize};
 #[cfg(feature = "server")]
 #[cfg(feature = "server")]
 #[tokio::main]
 #[tokio::main]
 async fn main() {
 async fn main() {
-    pre_cache_static_routes(
-        &ServeConfig::new_with_router(
-            dioxus_fullstack::router::FullstackRouterConfig::<Route>::default(),
-        )
-        .assets_path("docs")
-        .incremental(IncrementalRendererConfig::default().static_dir("docs"))
-        .build(),
-    )
-    .await
-    .unwrap();
+    let wrapper = DefaultRenderer {
+        before_body: r#"<!DOCTYPE html>
+    <html lang="en">
+    <head>
+        <meta charset="UTF-8">
+        <meta name="viewport" content="width=device-width,
+        initial-scale=1.0">
+        <title>Dioxus Application</title>
+    </head>
+    <body>"#
+            .to_string(),
+        after_body: r#"</body>
+    </html>"#
+            .to_string(),
+    };
+    let mut renderer = IncrementalRenderer::builder().build();
+    pre_cache_static_routes::<Route, _>(&mut renderer, &wrapper)
+        .await
+        .unwrap();
 }
 }
 
 
 // Hydrate the page
 // Hydrate the page

+ 3 - 2
packages/fullstack/src/axum_adapter.rs

@@ -361,7 +361,8 @@ pub async fn render_handler_with_context<F: FnMut(&mut DioxusServerContext)>(
 ) -> impl IntoResponse {
 ) -> impl IntoResponse {
     let (parts, _) = request.into_parts();
     let (parts, _) = request.into_parts();
     let url = parts.uri.path_and_query().unwrap().to_string();
     let url = parts.uri.path_and_query().unwrap().to_string();
-    let parts: Arc<RwLock<http::request::Parts>> = Arc::new(RwLock::new(parts.into()));
+    let parts: Arc<tokio::sync::RwLock<http::request::Parts>> =
+        Arc::new(tokio::sync::RwLock::new(parts.into()));
     let mut server_context = DioxusServerContext::new(parts.clone());
     let mut server_context = DioxusServerContext::new(parts.clone());
     inject_context(&mut server_context);
     inject_context(&mut server_context);
 
 
@@ -483,7 +484,7 @@ async fn handle_server_fns_inner(
             server_fn::axum::get_server_fn_service(&path_string)
             server_fn::axum::get_server_fn_service(&path_string)
         {
         {
 
 
-            let server_context = DioxusServerContext::new(Arc::new(RwLock::new(parts)));
+            let server_context = DioxusServerContext::new(Arc::new(tokio::sync::RwLock::new(parts)));
             additional_context();
             additional_context();
 
 
             // store Accepts and Referrer in case we need them for redirect (below)
             // store Accepts and Referrer in case we need them for redirect (below)

+ 13 - 15
packages/fullstack/src/server_context.rs

@@ -12,7 +12,7 @@ pub struct DioxusServerContext {
         std::sync::RwLock<anymap::Map<dyn anymap::any::Any + Send + Sync + 'static>>,
         std::sync::RwLock<anymap::Map<dyn anymap::any::Any + Send + Sync + 'static>>,
     >,
     >,
     response_parts: std::sync::Arc<std::sync::RwLock<http::response::Parts>>,
     response_parts: std::sync::Arc<std::sync::RwLock<http::response::Parts>>,
-    pub(crate) parts: Arc<RwLock<http::request::Parts>>,
+    pub(crate) parts: Arc<tokio::sync::RwLock<http::request::Parts>>,
     html_data: Arc<RwLock<HTMLData>>,
     html_data: Arc<RwLock<HTMLData>>,
 }
 }
 
 
@@ -24,7 +24,9 @@ impl Default for DioxusServerContext {
             response_parts: std::sync::Arc::new(RwLock::new(
             response_parts: std::sync::Arc::new(RwLock::new(
                 http::response::Response::new(()).into_parts().0,
                 http::response::Response::new(()).into_parts().0,
             )),
             )),
-            parts: std::sync::Arc::new(RwLock::new(http::request::Request::new(()).into_parts().0)),
+            parts: std::sync::Arc::new(tokio::sync::RwLock::new(
+                http::request::Request::new(()).into_parts().0,
+            )),
             html_data: Arc::new(RwLock::new(HTMLData::default())),
             html_data: Arc::new(RwLock::new(HTMLData::default())),
         }
         }
     }
     }
@@ -40,7 +42,7 @@ mod server_fn_impl {
 
 
     impl DioxusServerContext {
     impl DioxusServerContext {
         /// Create a new server context from a request
         /// Create a new server context from a request
-        pub fn new(parts: impl Into<Arc<RwLock<http::request::Parts>>>) -> Self {
+        pub fn new(parts: impl Into<Arc<tokio::sync::RwLock<http::request::Parts>>>) -> Self {
             Self {
             Self {
                 parts: parts.into(),
                 parts: parts.into(),
                 shared_context: Arc::new(RwLock::new(SendSyncAnyMap::new())),
                 shared_context: Arc::new(RwLock::new(SendSyncAnyMap::new())),
@@ -82,19 +84,15 @@ mod server_fn_impl {
         /// Get the request that triggered:
         /// Get the request that triggered:
         /// - The initial SSR render if called from a ScopeState or ServerFn
         /// - 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
         /// - The server function to be called if called from a server function after the initial render
-        pub fn request_parts(
-            &self,
-        ) -> std::sync::LockResult<RwLockReadGuard<'_, http::request::Parts>> {
-            self.parts.read()
+        pub fn request_parts(&self) -> tokio::sync::RwLockReadGuard<'_, http::request::Parts> {
+            self.parts.blocking_read()
         }
         }
 
 
         /// Get the request that triggered:
         /// Get the request that triggered:
         /// - The initial SSR render if called from a ScopeState or ServerFn
         /// - 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
         /// - The server function to be called if called from a server function after the initial render
-        pub fn request_parts_mut(
-            &self,
-        ) -> std::sync::LockResult<RwLockWriteGuard<'_, http::request::Parts>> {
-            self.parts.write()
+        pub fn request_parts_mut(&self) -> tokio::sync::RwLockWriteGuard<'_, http::request::Parts> {
+            self.parts.blocking_write()
         }
         }
 
 
         /// Extract some part from the request
         /// Extract some part from the request
@@ -185,7 +183,7 @@ impl<F: std::future::Future> std::future::Future for ProvideServerContext<F> {
 }
 }
 
 
 /// A trait for extracting types from the server context
 /// A trait for extracting types from the server context
-#[async_trait::async_trait(?Send)]
+#[async_trait::async_trait]
 pub trait FromServerContext<I = ()>: Sized {
 pub trait FromServerContext<I = ()>: Sized {
     /// The error type returned when extraction fails. This type must implement `std::error::Error`.
     /// The error type returned when extraction fails. This type must implement `std::error::Error`.
     type Rejection: std::error::Error;
     type Rejection: std::error::Error;
@@ -215,7 +213,7 @@ impl<T: 'static> std::error::Error for NotFoundInServerContext<T> {}
 
 
 pub struct FromContext<T: std::marker::Send + std::marker::Sync + Clone + 'static>(pub(crate) T);
 pub struct FromContext<T: std::marker::Send + std::marker::Sync + Clone + 'static>(pub(crate) T);
 
 
-#[async_trait::async_trait(?Send)]
+#[async_trait::async_trait]
 impl<T: Send + Sync + Clone + 'static> FromServerContext for FromContext<T> {
 impl<T: Send + Sync + Clone + 'static> FromServerContext for FromContext<T> {
     type Rejection = NotFoundInServerContext<T>;
     type Rejection = NotFoundInServerContext<T>;
 
 
@@ -232,7 +230,7 @@ impl<T: Send + Sync + Clone + 'static> FromServerContext for FromContext<T> {
 pub struct Axum;
 pub struct Axum;
 
 
 #[cfg(feature = "axum")]
 #[cfg(feature = "axum")]
-#[async_trait::async_trait(?Send)]
+#[async_trait::async_trait]
 impl<
 impl<
         I: axum::extract::FromRequestParts<(), Rejection = R>,
         I: axum::extract::FromRequestParts<(), Rejection = R>,
         R: axum::response::IntoResponse + std::error::Error,
         R: axum::response::IntoResponse + std::error::Error,
@@ -241,6 +239,6 @@ impl<
     type Rejection = R;
     type Rejection = R;
 
 
     async fn from_request(req: &DioxusServerContext) -> Result<Self, Self::Rejection> {
     async fn from_request(req: &DioxusServerContext) -> Result<Self, Self::Rejection> {
-        Ok(I::from_request_parts(&mut *req.request_parts_mut().unwrap(), &()).await?)
+        Ok(I::from_request_parts(&mut *req.request_parts_mut(), &()).await?)
     }
     }
 }
 }

+ 61 - 56
packages/router/benches/incremental.rs

@@ -11,24 +11,25 @@ use dioxus_ssr::Renderer;
 
 
 pub fn criterion_benchmark(c: &mut Criterion) {
 pub fn criterion_benchmark(c: &mut Criterion) {
     c.bench_function("build 1000 routes", |b| {
     c.bench_function("build 1000 routes", |b| {
-        let mut renderer = IncrementalRenderer::builder(DefaultRenderer {
+        let mut renderer = IncrementalRenderer::builder()
+            .static_dir("./static")
+            .invalidate_after(Duration::from_secs(10))
+            .build();
+        let wrapper = DefaultRenderer {
             before_body: r#"<!DOCTYPE html>
             before_body: r#"<!DOCTYPE html>
-            <html lang="en">
-            <head>
-                <meta charset="UTF-8">
-                <meta name="viewport" content="width=device-width,
-                initial-scale=1.0">
-                <title>Dioxus Application</title>
-            </head>
-            <body>"#
+        <html lang="en">
+        <head>
+            <meta charset="UTF-8">
+            <meta name="viewport" content="width=device-width,
+            initial-scale=1.0">
+            <title>Dioxus Application</title>
+        </head>
+        <body>"#
                 .to_string(),
                 .to_string(),
             after_body: r#"</body>
             after_body: r#"</body>
-            </html>"#
+        </html>"#
                 .to_string(),
                 .to_string(),
-        })
-        .static_dir("./static")
-        .invalidate_after(Duration::from_secs(10))
-        .build();
+        };
 
 
         b.iter(|| {
         b.iter(|| {
             tokio::runtime::Runtime::new().unwrap().block_on(async {
             tokio::runtime::Runtime::new().unwrap().block_on(async {
@@ -37,7 +38,8 @@ pub fn criterion_benchmark(c: &mut Criterion) {
                         &mut renderer,
                         &mut renderer,
                         Route::Post { id },
                         Route::Post { id },
                         &mut tokio::io::sink(),
                         &mut tokio::io::sink(),
-                        |_| {},
+                        |_| Box::pin(async move {}),
+                        &wrapper,
                     )
                     )
                     .await
                     .await
                     .unwrap();
                     .unwrap();
@@ -47,34 +49,36 @@ pub fn criterion_benchmark(c: &mut Criterion) {
     });
     });
 
 
     c.bench_function("build 1000 routes no memory cache", |b| {
     c.bench_function("build 1000 routes no memory cache", |b| {
+        let wrapper = DefaultRenderer {
+            before_body: r#"<!DOCTYPE html>
+            <html lang="en">
+            <head>
+                <meta charset="UTF-8">
+                <meta name="viewport" content="width=device-width,
+                initial-scale=1.0">
+                <title>Dioxus Application</title>
+            </head>
+            <body>"#
+                .to_string(),
+            after_body: r#"</body>
+            </html>"#
+                .to_string(),
+        };
         b.to_async(tokio::runtime::Runtime::new().unwrap())
         b.to_async(tokio::runtime::Runtime::new().unwrap())
             .iter(|| async {
             .iter(|| async {
-                let mut renderer = IncrementalRenderer::builder(DefaultRenderer {
-                    before_body: r#"<!DOCTYPE html>
-                    <html lang="en">
-                    <head>
-                        <meta charset="UTF-8">
-                        <meta name="viewport" content="width=device-width,
-                        initial-scale=1.0">
-                        <title>Dioxus Application</title>
-                    </head>
-                    <body>"#
-                        .to_string(),
-                    after_body: r#"</body>
-                    </html>"#
-                        .to_string(),
-                })
-                .static_dir("./static")
-                .memory_cache_limit(0)
-                .invalidate_after(Duration::from_secs(10))
-                .build();
+                let mut renderer = IncrementalRenderer::builder()
+                    .static_dir("./static")
+                    .memory_cache_limit(0)
+                    .invalidate_after(Duration::from_secs(10))
+                    .build();
 
 
                 for id in 0..1000 {
                 for id in 0..1000 {
                     render_route(
                     render_route(
                         &mut renderer,
                         &mut renderer,
                         Route::Post { id },
                         Route::Post { id },
                         &mut tokio::io::sink(),
                         &mut tokio::io::sink(),
-                        |_| {},
+                        |_| Box::pin(async move {}),
+                        &wrapper,
                     )
                     )
                     .await
                     .await
                     .unwrap();
                     .unwrap();
@@ -91,7 +95,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
                     RenderPathProps::builder().path(Route::Post { id }).build(),
                     RenderPathProps::builder().path(Route::Post { id }).build(),
                 );
                 );
 
 
-                vdom.rebuild();
+                vdom.rebuild_in_place();
 
 
                 struct Ignore;
                 struct Ignore;
 
 
@@ -106,27 +110,28 @@ pub fn criterion_benchmark(c: &mut Criterion) {
         })
         })
     });
     });
     c.bench_function("cache static", |b| {
     c.bench_function("cache static", |b| {
+        let wrapper = DefaultRenderer {
+            before_body: r#"<!DOCTYPE html>
+        <html lang="en">
+        <head>
+            <meta charset="UTF-8">
+            <meta name="viewport" content="width=device-width,
+            initial-scale=1.0">
+            <title>Dioxus Application</title>
+        </head>
+        <body>"#
+                .to_string(),
+            after_body: r#"</body>
+        </html>"#
+                .to_string(),
+        };
         b.to_async(tokio::runtime::Runtime::new().unwrap())
         b.to_async(tokio::runtime::Runtime::new().unwrap())
             .iter(|| async {
             .iter(|| async {
-                let mut renderer = IncrementalRenderer::builder(DefaultRenderer {
-                    before_body: r#"<!DOCTYPE html>
-                <html lang="en">
-                <head>
-                    <meta charset="UTF-8">
-                    <meta name="viewport" content="width=device-width,
-                    initial-scale=1.0">
-                    <title>Dioxus Application</title>
-                </head>
-                <body>"#
-                        .to_string(),
-                    after_body: r#"</body>
-                </html>"#
-                        .to_string(),
-                })
-                .static_dir("./static")
-                .build();
-
-                pre_cache_static_routes::<Route, _>(&mut renderer)
+                let mut renderer = IncrementalRenderer::builder()
+                    .static_dir("./static")
+                    .build();
+
+                pre_cache_static_routes::<Route, _>(&mut renderer, &wrapper)
                     .await
                     .await
                     .unwrap();
                     .unwrap();
             })
             })
@@ -148,7 +153,7 @@ fn Blog() -> Element {
 #[component]
 #[component]
 fn Post(id: usize) -> Element {
 fn Post(id: usize) -> Element {
     rsx! {
     rsx! {
-        for _ in 0..*id {
+        for _ in 0..id {
             div {
             div {
                 "PostId: {id}"
                 "PostId: {id}"
             }
             }

+ 0 - 1
packages/router/src/router_cfg.rs

@@ -135,7 +135,6 @@ where
         MemoryHistory::<R>::with_initial_path(
         MemoryHistory::<R>::with_initial_path(
             dioxus_fullstack::prelude::server_context()
             dioxus_fullstack::prelude::server_context()
                 .request_parts()
                 .request_parts()
-                .unwrap()
                 .uri
                 .uri
                 .to_string()
                 .to_string()
                 .parse()
                 .parse()