Skip to content

Commit 5b59b78

Browse files
committed
adds feature server_fn_axum that compiles for wasm target
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
1 parent 7b73570 commit 5b59b78

File tree

10 files changed

+438
-360
lines changed

10 files changed

+438
-360
lines changed

Cargo.lock

+1-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ tauri-utils = { version = "=2.1.1" }
190190
tauri-bundler = { version = "=2.2.3" }
191191
lru = "0.12.2"
192192
async-trait = "0.1.77"
193-
axum = "0.7.0"
193+
axum = { version = "0.7.0", default-features = false }
194194
axum-server = { version = "0.7.1", default-features = false }
195195
tower = "0.4.13"
196196
http = "1.0.0"
@@ -347,6 +347,7 @@ rand = { version = "0.8.4", features = ["small_rng"] }
347347
form_urlencoded = "1.2.0"
348348
async-std = "1.12.0"
349349
web-time = "1.1.0"
350+
axum = { workspace = true, default-features = true }
350351

351352
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
352353
getrandom = { version = "0.2.12", features = ["js"] }

packages/cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ krates = { version = "0.17.0" }
5353
cargo-config2 = { workspace = true, optional = true }
5454
regex = "1.10.6"
5555

56-
axum = { workspace = true, features = ["ws"] }
56+
axum = { workspace = true, default-features = true, features = ["ws"] }
5757
axum-server = { workspace = true, features = ["tls-rustls"] }
5858
axum-extra = { workspace = true, features = ["typed-header"] }
5959
tower-http = { workspace = true, features = ["full"] }

packages/fullstack/Cargo.toml

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ server_fn = { version = "0.7.3", features = ["json", "url", "browser"], default-
1616
dioxus_server_macro = { workspace = true }
1717

1818
# axum
19-
axum = { workspace = true, features = ["ws", "macros"], optional = true }
19+
axum = { workspace = true, optional = true }
2020
tower-http = { workspace = true, optional = true, features = ["fs"] }
2121

2222
dioxus-lib = { workspace = true }
@@ -87,7 +87,18 @@ desktop = ["dep:dioxus-desktop", "server_fn/reqwest", "dioxus_server_macro/reqwe
8787
mobile = ["dep:dioxus-mobile", "server_fn/reqwest", "dioxus_server_macro/reqwest"]
8888
default-tls = ["server_fn/default-tls"]
8989
rustls = ["server_fn/rustls", "dep:rustls", "dep:hyper-rustls"]
90-
axum = ["dep:axum", "dep:tower-http", "server", "server_fn/axum", "dioxus_server_macro/axum", "default-tls"]
90+
axum_core = [
91+
"dep:axum",
92+
"server_fn/axum-no-default",
93+
"dioxus_server_macro/axum",
94+
"default-tls",
95+
"server",
96+
]
97+
axum = [
98+
"dep:tower-http",
99+
"server_fn/axum",
100+
"axum_core",
101+
]
91102
server = [
92103
"server_fn/ssr",
93104
"dioxus_server_macro/server",

0 commit comments

Comments
 (0)