adds feature server_fn_axum that compiles for wasm target (#3840)
The current `axum` feature and `server` feature are incompatible with wasm32-unknown-unknown target due to: 1. depends on axum features not compatible with wasm 2. SSR requires reading the filesystem for index.html With this patch I add the `server_fn_axum` feature which disables SSR and enables targeting wasm32-unknown-unknown with server functions enabled. Note that for this to work, `server_fn` depends on `inventory` and as stated in this docs depending on the context you might need to expose and call [`__wasm_call_ctors`](https://docs.rs/inventory/latest/inventory/#webassembly-and-constructors) (I needed that specifically for cloudflare workers) change axum_server_fn feature for axum_wasm and include SSR tools there This change additionaly make axum_server_fn feature additive by exposing a different `DioxusRouterWasmExt` with only the wasm-compatible parts instead of exposing the `DioxusRouter` trait under the same name. Docs are updated to reflect this change. rename axum_wasm to axum_core and update docs fix typo re-enable default-features for axum in dioxus-cli re-enable axum default-features for liveview re-enable default-features for axum for playwright-tests
This commit is contained in:
10 files changed
+446
-368
No files matched your search
@@ -8,8 +8,7 @@ use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub(crate) type ContextProviders =
|
||||
Arc<Vec<Box<dyn Fn() -> Box<dyn std::any::Any> + Send + Sync + 'static>>>;
|
||||
use crate::ContextProviders;
|
||||
|
||||
/// A ServeConfig is used to configure how to serve a Dioxus application. It contains information about how to serve static assets, and what content to render with [`dioxus-ssr`].
|
||||
#[derive(Clone, Default)]
|
||||
@@ -337,20 +336,24 @@ impl ServeConfigBuilder {
|
||||
}
|
||||
|
||||
/// Build the ServeConfig. This may fail if the index.html file is not found.
|
||||
///
|
||||
/// ## WASM compatibility
|
||||
/// In the context of WASM the file system normally can't be read so this always requires
|
||||
/// the `index_html` field to be set.
|
||||
pub fn build(self) -> Result<ServeConfig, UnableToLoadIndex> {
|
||||
// The CLI always bundles static assets into the exe/public directory
|
||||
let public_path = public_path();
|
||||
|
||||
let index_path = self
|
||||
.index_path
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| public_path.join("index.html"));
|
||||
|
||||
let root_id = self.root_id.unwrap_or("main");
|
||||
|
||||
let index_html = match self.index_html {
|
||||
Some(index) => index,
|
||||
None => load_index_path(index_path)?,
|
||||
None => {
|
||||
// The CLI always bundles static assets into the exe/public directory
|
||||
let public_path = public_path();
|
||||
|
||||
let index_path = self
|
||||
.index_path
|
||||
.unwrap_or_else(|| public_path.join("index.html"));
|
||||
load_index_path(index_path)?
|
||||
}
|
||||
};
|
||||
|
||||
let index = load_index_html(index_html, root_id);
|
||||
@@ -491,6 +494,7 @@ impl LaunchConfig for ServeConfig {}
|
||||
|
||||
impl ServeConfig {
|
||||
/// Create a new ServeConfig
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
pub fn new() -> Result<Self, UnableToLoadIndex> {
|
||||
ServeConfigBuilder::new().build()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user