allow passing props to the rendered component

This commit is contained in:
Evan Almloff committed 2023-03-30 19:42:46 -05:00
1 parent 39a5fbf268
commit f618da7311
6 files changed
+19 -10

No files matched your search

+2 -1
View File
@@ -23,7 +23,8 @@ members = [
"packages/hot-reload", "packages/hot-reload",
"packages/server", "packages/server",
"packages/server/server-macro", "packages/server/server-macro",
"packages/server/examples/hello-world", "packages/server/examples/axum-hello-world",
"packages/server/examples/salvo-hello-world",
"docs/guide", "docs/guide",
] ]
+3 -3
View File
@@ -13,12 +13,12 @@ server_macro = { path = "server-macro" }
warp = { version = "0.3.3", optional = true } warp = { version = "0.3.3", optional = true }
# axum # axum
axum = { version = "0.6.1", optional = true, features = ["ws"] } axum = { version = "0.6.1", optional = true }
tower-http = { version = "0.4.0", optional = true, features = ["fs"] } tower-http = { version = "0.4.0", optional = true, features = ["fs"] }
hyper = { version = "0.14.25", optional = true } hyper = { version = "0.14.25", optional = true }
# salvo # salvo
salvo = { version = "0.37.7", optional = true, features = ["ws"] } salvo = { version = "0.37.7", optional = true, features = ["serve-static"] }
serde = "1.0.159" serde = "1.0.159"
dioxus-core = { path = "../core", version = "^0.3.0" } dioxus-core = { path = "../core", version = "^0.3.0" }
@@ -33,5 +33,5 @@ tokio = { version = "1.27.0", features = ["full"], optional = true }
default = [] default = []
warp = ["dep:warp"] warp = ["dep:warp"]
axum = ["dep:axum", "tower-http", "hyper"] axum = ["dep:axum", "tower-http", "hyper"]
salvo = ["dep:salvo"] salvo = ["dep:salvo", "hyper"]
ssr = ["server_fn/ssr", "tokio", "dioxus-ssr"] ssr = ["server_fn/ssr", "tokio", "dioxus-ssr"]
+2
View File
@@ -1,2 +1,4 @@
#[cfg(feature = "axum")] #[cfg(feature = "axum")]
pub mod axum_adapter; pub mod axum_adapter;
#[cfg(feature = "salvo")]
pub mod salvo_adapter;
+5 -2
View File
@@ -9,6 +9,8 @@ mod server_fn;
pub mod prelude { pub mod prelude {
#[cfg(feature = "axum")] #[cfg(feature = "axum")]
pub use crate::adapters::axum_adapter::*; pub use crate::adapters::axum_adapter::*;
#[cfg(feature = "salvo")]
pub use crate::adapters::salvo_adapter::*;
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
pub use crate::serve::ServeConfig; pub use crate::serve::ServeConfig;
pub use crate::server_fn::{DioxusServerContext, ServerFn}; pub use crate::server_fn::{DioxusServerContext, ServerFn};
@@ -17,7 +19,7 @@ pub mod prelude {
} }
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
fn dioxus_ssr_html(cfg: serve::ServeConfig) -> String { fn dioxus_ssr_html<P: 'static + Clone>(cfg: &serve::ServeConfig<P>) -> String {
use prelude::ServeConfig; use prelude::ServeConfig;
let ServeConfig { let ServeConfig {
@@ -25,12 +27,13 @@ fn dioxus_ssr_html(cfg: serve::ServeConfig) -> String {
application_name, application_name,
base_path, base_path,
head, head,
props,
.. ..
} = cfg; } = cfg;
let application_name = application_name.unwrap_or("dioxus"); let application_name = application_name.unwrap_or("dioxus");
let mut vdom = VirtualDom::new(app); let mut vdom = VirtualDom::new_with_props(*app, props.clone());
let _ = vdom.rebuild(); let _ = vdom.rebuild();
let renderered = dioxus_ssr::pre_render(&vdom); let renderered = dioxus_ssr::pre_render(&vdom);
let base_path = base_path.unwrap_or("."); let base_path = base_path.unwrap_or(".");
+6 -4
View File
@@ -1,19 +1,21 @@
use dioxus_core::Component; use dioxus_core::Component;
#[derive(Clone)] #[derive(Clone)]
pub struct ServeConfig { pub struct ServeConfig<P: Clone> {
pub(crate) app: Component, pub(crate) app: Component<P>,
pub(crate) props: P,
pub(crate) application_name: Option<&'static str>, pub(crate) application_name: Option<&'static str>,
pub(crate) server_fn_route: Option<&'static str>, pub(crate) server_fn_route: Option<&'static str>,
pub(crate) base_path: Option<&'static str>, pub(crate) base_path: Option<&'static str>,
pub(crate) head: Option<&'static str>, pub(crate) head: Option<&'static str>,
} }
impl ServeConfig { impl<P: Clone> ServeConfig<P> {
/// Create a new ServeConfig /// Create a new ServeConfig
pub fn new(app: Component) -> Self { pub fn new(app: Component<P>, props: P) -> Self {
Self { Self {
app, app,
props,
application_name: None, application_name: None,
server_fn_route: None, server_fn_route: None,
base_path: None, base_path: None,
+1
View File
@@ -1,3 +1,4 @@
#[derive(Clone)]
pub struct DioxusServerContext {} pub struct DioxusServerContext {}
#[cfg(any(feature = "ssr", doc))] #[cfg(any(feature = "ssr", doc))]