fix cargo check all features except the router
This commit is contained in:
1 parent
2952578a2e
commit
14b4af4bbc
7 files changed
+105
-93
No files matched your search
@@ -7,7 +7,7 @@ publish = false
|
||||
[lib]
|
||||
|
||||
[dependencies]
|
||||
dioxus = { workspace = true, features = ["launch"] }
|
||||
dioxus = { workspace = true, features = ["launch", "fullstack"] }
|
||||
axum = { workspace = true, optional = true }
|
||||
tokio = { workspace = true, features = ["full"], optional = true }
|
||||
serde = "1.0.159"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
use axum_desktop::*;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_fullstack::server_fn::axum::register_explicit;
|
||||
use server_fn::axum::register_explicit;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
||||
@@ -14,16 +14,25 @@ use serde::{Deserialize, Serialize};
|
||||
#[cfg(feature = "server")]
|
||||
#[tokio::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
|
||||
|
||||
@@ -361,7 +361,8 @@ pub async fn render_handler_with_context<F: FnMut(&mut DioxusServerContext)>(
|
||||
) -> impl IntoResponse {
|
||||
let (parts, _) = request.into_parts();
|
||||
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());
|
||||
inject_context(&mut server_context);
|
||||
|
||||
@@ -483,7 +484,7 @@ async fn handle_server_fns_inner(
|
||||
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();
|
||||
|
||||
// store Accepts and Referrer in case we need them for redirect (below)
|
||||
|
||||
@@ -12,7 +12,7 @@ pub struct DioxusServerContext {
|
||||
std::sync::RwLock<anymap::Map<dyn anymap::any::Any + Send + Sync + 'static>>,
|
||||
>,
|
||||
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>>,
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ impl Default for DioxusServerContext {
|
||||
response_parts: std::sync::Arc::new(RwLock::new(
|
||||
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())),
|
||||
}
|
||||
}
|
||||
@@ -40,7 +42,7 @@ mod server_fn_impl {
|
||||
|
||||
impl DioxusServerContext {
|
||||
/// 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 {
|
||||
parts: parts.into(),
|
||||
shared_context: Arc::new(RwLock::new(SendSyncAnyMap::new())),
|
||||
@@ -82,19 +84,15 @@ 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,
|
||||
) -> 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:
|
||||
/// - 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,
|
||||
) -> 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
|
||||
@@ -185,7 +183,7 @@ impl<F: std::future::Future> std::future::Future for ProvideServerContext<F> {
|
||||
}
|
||||
|
||||
/// A trait for extracting types from the server context
|
||||
#[async_trait::async_trait(?Send)]
|
||||
#[async_trait::async_trait]
|
||||
pub trait FromServerContext<I = ()>: Sized {
|
||||
/// The error type returned when extraction fails. This type must implement `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);
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
#[async_trait::async_trait]
|
||||
impl<T: Send + Sync + Clone + 'static> FromServerContext for FromContext<T> {
|
||||
type Rejection = NotFoundInServerContext<T>;
|
||||
|
||||
@@ -232,7 +230,7 @@ impl<T: Send + Sync + Clone + 'static> FromServerContext for FromContext<T> {
|
||||
pub struct Axum;
|
||||
|
||||
#[cfg(feature = "axum")]
|
||||
#[async_trait::async_trait(?Send)]
|
||||
#[async_trait::async_trait]
|
||||
impl<
|
||||
I: axum::extract::FromRequestParts<(), Rejection = R>,
|
||||
R: axum::response::IntoResponse + std::error::Error,
|
||||
@@ -241,6 +239,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().unwrap(), &()).await?)
|
||||
Ok(I::from_request_parts(&mut *req.request_parts_mut(), &()).await?)
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,45 @@ use dioxus_ssr::Renderer;
|
||||
|
||||
pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
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>
|
||||
<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.iter(|| {
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
for id in 0..1000 {
|
||||
render_route(
|
||||
&mut renderer,
|
||||
Route::Post { id },
|
||||
&mut tokio::io::sink(),
|
||||
|_| Box::pin(async move {}),
|
||||
&wrapper,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("build 1000 routes no memory cache", |b| {
|
||||
let wrapper = DefaultRenderer {
|
||||
before_body: r#"<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@@ -25,56 +63,22 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
after_body: r#"</body>
|
||||
</html>"#
|
||||
.to_string(),
|
||||
})
|
||||
.static_dir("./static")
|
||||
.invalidate_after(Duration::from_secs(10))
|
||||
.build();
|
||||
|
||||
b.iter(|| {
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
for id in 0..1000 {
|
||||
render_route(
|
||||
&mut renderer,
|
||||
Route::Post { id },
|
||||
&mut tokio::io::sink(),
|
||||
|_| {},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("build 1000 routes no memory cache", |b| {
|
||||
};
|
||||
b.to_async(tokio::runtime::Runtime::new().unwrap())
|
||||
.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 {
|
||||
render_route(
|
||||
&mut renderer,
|
||||
Route::Post { id },
|
||||
&mut tokio::io::sink(),
|
||||
|_| {},
|
||||
|_| Box::pin(async move {}),
|
||||
&wrapper,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -91,7 +95,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
RenderPathProps::builder().path(Route::Post { id }).build(),
|
||||
);
|
||||
|
||||
vdom.rebuild();
|
||||
vdom.rebuild_in_place();
|
||||
|
||||
struct Ignore;
|
||||
|
||||
@@ -106,27 +110,28 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
})
|
||||
});
|
||||
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())
|
||||
.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();
|
||||
let mut renderer = IncrementalRenderer::builder()
|
||||
.static_dir("./static")
|
||||
.build();
|
||||
|
||||
pre_cache_static_routes::<Route, _>(&mut renderer)
|
||||
pre_cache_static_routes::<Route, _>(&mut renderer, &wrapper)
|
||||
.await
|
||||
.unwrap();
|
||||
})
|
||||
@@ -148,7 +153,7 @@ fn Blog() -> Element {
|
||||
#[component]
|
||||
fn Post(id: usize) -> Element {
|
||||
rsx! {
|
||||
for _ in 0..*id {
|
||||
for _ in 0..id {
|
||||
div {
|
||||
"PostId: {id}"
|
||||
}
|
||||
|
||||
@@ -135,7 +135,6 @@ where
|
||||
MemoryHistory::<R>::with_initial_path(
|
||||
dioxus_fullstack::prelude::server_context()
|
||||
.request_parts()
|
||||
.unwrap()
|
||||
.uri
|
||||
.to_string()
|
||||
.parse()
|
||||
|
||||
Reference in new issue
Block a user