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:
Gabi authored and GitHub committed 2025-03-27 00:51:53 -06:00
1 parent dc0f0dbd2c
commit dfc359cdfb
10 files changed
+446 -368

No files matched your search

+13 -2
View File
@@ -16,7 +16,7 @@ server_fn = { version = "0.7.3", features = ["json", "url", "browser"], default-
dioxus_server_macro = { workspace = true }
# axum
axum = { workspace = true, features = ["ws", "macros"], optional = true }
axum = { workspace = true, optional = true }
tower-http = { workspace = true, optional = true, features = ["fs"] }
dioxus-lib = { workspace = true }
@@ -88,7 +88,18 @@ desktop = ["dep:dioxus-desktop", "server_fn/reqwest", "dioxus_server_macro/reqwe
mobile = ["dep:dioxus-mobile", "server_fn/reqwest", "dioxus_server_macro/reqwest"]
default-tls = ["server_fn/default-tls"]
rustls = ["server_fn/rustls", "dep:rustls", "dep:hyper-rustls"]
axum = ["dep:axum", "dep:tower-http", "server", "server_fn/axum", "dioxus_server_macro/axum", "default-tls"]
axum_core = [
"dep:axum",
"server_fn/axum-no-default",
"dioxus_server_macro/axum",
"default-tls",
"server",
]
axum = [
"dep:tower-http",
"server_fn/axum",
"axum_core",
]
server = [
"server_fn/ssr",
"dioxus_server_macro/server",