From 57e95258857131f9ac3d7466251131f026683383 Mon Sep 17 00:00:00 2001 From: Ryo Hirayama Date: Sat, 7 Jun 2025 23:47:00 +0900 Subject: [PATCH 1/3] Use leptos:ws-test2 --- Cargo.lock | 45 ++++++++++++++++++----------- Cargo.toml | 6 ++-- examples/fullstack-wasm/Cargo.toml | 13 +++++++++ examples/fullstack-wasm/README.md | 5 ++++ examples/fullstack-wasm/src/main.rs | 18 ++++++++++++ packages/dioxus/Cargo.toml | 9 ++++++ packages/fullstack/Cargo.toml | 3 +- packages/server/src/render.rs | 10 +++---- 8 files changed, 83 insertions(+), 26 deletions(-) create mode 100644 examples/fullstack-wasm/Cargo.toml create mode 100644 examples/fullstack-wasm/README.md create mode 100644 examples/fullstack-wasm/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index aa47f7c128..cbae496105 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4360,13 +4360,6 @@ dependencies = [ "winit", ] -[[package]] -name = "dioxus-playwright-default-features-disabled-test" -version = "0.1.0" -dependencies = [ - "dioxus", -] - [[package]] name = "dioxus-playwright-fullstack-mounted-test" version = "0.1.0" @@ -4647,7 +4640,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "server_fn_macro", + "server_fn_macro 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 2.0.101", "tower-http", ] @@ -5630,6 +5623,13 @@ dependencies = [ "tokio", ] +[[package]] +name = "fullstack-wasm" +version = "0.7.0-alpha.1" +dependencies = [ + "dioxus", +] + [[package]] name = "fullstack-websocket-example" version = "0.1.0" @@ -12421,9 +12421,9 @@ dependencies = [ [[package]] name = "serde_qs" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b417bedc008acbdf6d6b4bc482d29859924114bbe2650b7921fb68a261d0aa6" +checksum = "f3faaf9e727533a19351a43cc5a8de957372163c7d35cc48c90b75cdda13c352" dependencies = [ "percent-encoding", "serde", @@ -12508,8 +12508,7 @@ dependencies = [ [[package]] name = "server_fn" version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b0f92b9d3a62c73f238ac21f7a09f15bad335a9d1651514d9da80d2eaf8d4c" +source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#0185dab999acea569bb25cc3ffe6cdaa1a776142" dependencies = [ "axum 0.8.4", "base64 0.22.1", @@ -12563,13 +12562,26 @@ dependencies = [ "xxhash-rust", ] +[[package]] +name = "server_fn_macro" +version = "0.8.2" +source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#0185dab999acea569bb25cc3ffe6cdaa1a776142" +dependencies = [ + "const_format", + "convert_case 0.8.0", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.101", + "xxhash-rust", +] + [[package]] name = "server_fn_macro_default" version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5ab934f581482a66da82f2b57b15390ad67c9ab85bd9a6c54bb65060fb1380" +source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#0185dab999acea569bb25cc3ffe6cdaa1a776142" dependencies = [ - "server_fn_macro", + "server_fn_macro 0.8.2 (git+https://github.com/ryo33/leptos.git?branch=test-ws2)", "syn 2.0.101", ] @@ -14567,8 +14579,7 @@ dependencies = [ [[package]] name = "throw_error" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41e42a6afdde94f3e656fae18f837cb9bbe500a5ac5de325b09f3ec05b9c28e3" +source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#0185dab999acea569bb25cc3ffe6cdaa1a776142" dependencies = [ "pin-project-lite", ] diff --git a/Cargo.toml b/Cargo.toml index 874c6f83ef..7e0eb9f24d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -113,6 +113,7 @@ members = [ "examples/fullstack-desktop", "examples/fullstack-auth", "examples/fullstack-websockets", + "examples/fullstack-wasm", # Playwright tests "packages/playwright-tests/liveview", @@ -126,7 +127,6 @@ members = [ "packages/playwright-tests/nested-suspense", "packages/playwright-tests/cli-optimization", "packages/playwright-tests/wasm-split-harness", - "packages/playwright-tests/default-features-disabled", ] [workspace.package] @@ -164,7 +164,7 @@ dioxus-cli-config = { path = "packages/cli-config", version = "0.7.0-alpha.1" } dioxus-cli-opt = { path = "packages/cli-opt", version = "0.7.0-alpha.1" } dioxus-devtools = { path = "packages/devtools", version = "0.7.0-alpha.1" } dioxus-devtools-types = { path = "packages/devtools-types", version = "0.7.0-alpha.1" } -dioxus-server = { path = "packages/server", version = "0.7.0-alpha.1" } +dioxus-server = { path = "packages/server", version = "0.7.0-alpha.1", default-features = false } dioxus-fullstack = { path = "packages/fullstack", version = "0.7.0-alpha.1" } dioxus-fullstack-hooks = { path = "packages/fullstack-hooks", version = "0.7.0-alpha.1" } dioxus-fullstack-protocol = { path = "packages/fullstack-protocol", version = "0.7.0-alpha.1" } @@ -231,7 +231,7 @@ lru = "0.13.0" async-trait = "0.1.87" axum = { version = "0.8.1", default-features = false } axum-server = { version = "0.7.1", default-features = false } -server_fn = { version = "0.8.2", default-features = false } +server_fn = { git = "https://github.com/ryo33/leptos.git", branch = "test-ws2", default-features = false } server_fn_macro = { version = "0.8.2" } tower = "0.5.2" http = "1.2.0" diff --git a/examples/fullstack-wasm/Cargo.toml b/examples/fullstack-wasm/Cargo.toml new file mode 100644 index 0000000000..5f95b63303 --- /dev/null +++ b/examples/fullstack-wasm/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "fullstack-wasm" +edition = "2024" +version.workspace = true + +[features] +web = ["dioxus/web"] +server = ["dioxus/server-core"] + +[dependencies] +dioxus = { workspace = true, features = [ + "fullstack", +] } diff --git a/examples/fullstack-wasm/README.md b/examples/fullstack-wasm/README.md new file mode 100644 index 0000000000..4fa98b7cd0 --- /dev/null +++ b/examples/fullstack-wasm/README.md @@ -0,0 +1,5 @@ +# Fullstack WASM + +```sh +dx build --platform server --target wasm32-unknown-unknown +``` diff --git a/examples/fullstack-wasm/src/main.rs b/examples/fullstack-wasm/src/main.rs new file mode 100644 index 0000000000..0a37392b30 --- /dev/null +++ b/examples/fullstack-wasm/src/main.rs @@ -0,0 +1,18 @@ +use dioxus::prelude::*; + +fn main() { + dioxus::launch(app); +} + +#[server] +async fn hello_world() -> Result { + Ok("Hello, world!".to_string()) +} + +fn app() -> Element { + let hello_world = use_server_future(hello_world)?; + let hello_world = hello_world().unwrap().unwrap(); + rsx! { + "Hello, world! {hello_world}" + } +} diff --git a/packages/dioxus/Cargo.toml b/packages/dioxus/Cargo.toml index cf1992a5f9..81644a39c8 100644 --- a/packages/dioxus/Cargo.toml +++ b/packages/dioxus/Cargo.toml @@ -100,6 +100,15 @@ server = [ "dioxus-liveview?/axum", "dioxus-fullstack?/server", ] +server-core = [ + "dep:dioxus-server", + "dep:dioxus_server_macro", + "dioxus_server_macro/server", + "dioxus_server_macro/axum", + "ssr", + "dioxus-liveview?/axum", + "dioxus-fullstack?/server-core", +] # This feature just disables the no-renderer-enabled warning third-party-renderer = [] diff --git a/packages/fullstack/Cargo.toml b/packages/fullstack/Cargo.toml index a2d793a641..b2cc5d6e6c 100644 --- a/packages/fullstack/Cargo.toml +++ b/packages/fullstack/Cargo.toml @@ -92,11 +92,12 @@ server = [ "server-core" , "default-tls", "server_fn/axum", + "server_fn/reqwest", ] server-core = [ "server_fn/axum-no-default", "dioxus_server_macro/axum", - "server_fn/reqwest", + "server_fn/reqwest-no-ws", "server_fn/ssr", "dioxus_server_macro/reqwest", "dioxus-fullstack-hooks/server", diff --git a/packages/server/src/render.rs b/packages/server/src/render.rs index f69f722e4d..1fbaf5e0cf 100644 --- a/packages/server/src/render.rs +++ b/packages/server/src/render.rs @@ -658,11 +658,11 @@ impl FullstackHTMLTemplate { to.write_str(&index.close_head)?; - // // #[cfg(feature = "document")] - // { - use dioxus_interpreter_js::INITIALIZE_STREAMING_JS; - write!(to, "")?; - // } + #[cfg(feature = "document")] + { + use dioxus_interpreter_js::INITIALIZE_STREAMING_JS; + write!(to, "")?; + } Ok(()) } From 4b270a43a587a6b2e5c284648589e5252a1035d2 Mon Sep 17 00:00:00 2001 From: Ryo Hirayama Date: Mon, 9 Jun 2025 16:23:36 +0900 Subject: [PATCH 2/3] not pretty, but npx wrangler dev works now --- Cargo.lock | 119 ++++++++++++++++++++++--- examples/fullstack-wasm/Cargo.toml | 14 ++- examples/fullstack-wasm/dummy/.gitkeep | 0 examples/fullstack-wasm/src/lib.rs | 49 ++++++++++ examples/fullstack-wasm/src/main.rs | 16 +--- examples/fullstack-wasm/wrangler.toml | 8 ++ packages/fullstack/Cargo.toml | 1 + packages/fullstack/src/lib.rs | 4 +- packages/server/Cargo.toml | 2 + packages/server/src/config.rs | 21 +++-- packages/server/src/render.rs | 39 +++++++- 11 files changed, 234 insertions(+), 39 deletions(-) create mode 100644 examples/fullstack-wasm/dummy/.gitkeep create mode 100644 examples/fullstack-wasm/src/lib.rs create mode 100644 examples/fullstack-wasm/wrangler.toml diff --git a/Cargo.lock b/Cargo.lock index cbae496105..de6ce9b388 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1482,7 +1482,7 @@ dependencies = [ "bitflags 2.9.1", "cexpr", "clang-sys", - "itertools 0.12.1", + "itertools 0.10.5", "lazy_static", "lazycell", "log", @@ -3346,7 +3346,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e3d747f100290a1ca24b752186f61f6637e1deffe3bf6320de6fcb29510a307" dependencies = [ "bitflags 2.9.1", - "libloading 0.8.7", + "libloading 0.7.4", "winapi", ] @@ -4529,6 +4529,7 @@ dependencies = [ "dioxus-ssr", "enumset", "futures-channel", + "futures-executor", "futures-util", "generational-box", "http 1.3.1", @@ -4551,6 +4552,7 @@ dependencies = [ "tower-layer", "tracing", "tracing-futures", + "wasm-bindgen-futures", "web-sys", ] @@ -4621,7 +4623,7 @@ dependencies = [ "lazy-js-bundle", "rustc-hash 2.1.1", "serde", - "serde-wasm-bindgen", + "serde-wasm-bindgen 0.6.5", "serde_json", "tracing", "tracing-wasm", @@ -4749,7 +4751,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" dependencies = [ - "libloading 0.8.7", + "libloading 0.7.4", ] [[package]] @@ -5627,7 +5629,12 @@ dependencies = [ name = "fullstack-wasm" version = "0.7.0-alpha.1" dependencies = [ + "axum 0.8.4", + "console_error_panic_hook", "dioxus", + "tower-service", + "wasm-bindgen", + "worker", ] [[package]] @@ -6871,7 +6878,7 @@ dependencies = [ "bitflags 2.9.1", "com", "libc", - "libloading 0.8.7", + "libloading 0.7.4", "thiserror 1.0.69", "widestring", "winapi", @@ -8302,7 +8309,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a793df0d7afeac54f95b471d3af7f0d4fb975699f972341a4b76988d49cdf0c" dependencies = [ "cfg-if", - "windows-targets 0.53.0", + "windows-targets 0.48.5", ] [[package]] @@ -10365,7 +10372,7 @@ dependencies = [ "aes-gcm", "aes-kw", "argon2", - "base64 0.22.1", + "base64 0.21.7", "bitfield", "block-padding", "blowfish", @@ -12363,6 +12370,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3b143e2833c57ab9ad3ea280d21fd34e285a42837aeb0ee301f4f41890fa00e" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde-wasm-bindgen" version = "0.6.5" @@ -12508,7 +12526,7 @@ dependencies = [ [[package]] name = "server_fn" version = "0.8.2" -source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#0185dab999acea569bb25cc3ffe6cdaa1a776142" +source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#cae23e008e71b44a94c20f05d4581259c2dba9c5" dependencies = [ "axum 0.8.4", "base64 0.22.1", @@ -12565,7 +12583,7 @@ dependencies = [ [[package]] name = "server_fn_macro" version = "0.8.2" -source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#0185dab999acea569bb25cc3ffe6cdaa1a776142" +source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#cae23e008e71b44a94c20f05d4581259c2dba9c5" dependencies = [ "const_format", "convert_case 0.8.0", @@ -12579,7 +12597,7 @@ dependencies = [ [[package]] name = "server_fn_macro_default" version = "0.8.2" -source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#0185dab999acea569bb25cc3ffe6cdaa1a776142" +source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#cae23e008e71b44a94c20f05d4581259c2dba9c5" dependencies = [ "server_fn_macro 0.8.2 (git+https://github.com/ryo33/leptos.git?branch=test-ws2)", "syn 2.0.101", @@ -14579,7 +14597,7 @@ dependencies = [ [[package]] name = "throw_error" version = "0.3.0" -source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#0185dab999acea569bb25cc3ffe6cdaa1a776142" +source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#cae23e008e71b44a94c20f05d4581259c2dba9c5" dependencies = [ "pin-project-lite", ] @@ -16516,7 +16534,7 @@ dependencies = [ "js-sys", "khronos-egl", "libc", - "libloading 0.8.7", + "libloading 0.7.4", "log", "metal 0.27.0", "naga 0.19.2", @@ -16689,7 +16707,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.48.0", ] [[package]] @@ -17358,6 +17376,81 @@ dependencies = [ "bitflags 2.9.1", ] +[[package]] +name = "worker" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "727789ca7eff9733efbea9d0e97779edc1cf1926e98aee7d7d8afe32805458aa" +dependencies = [ + "async-trait", + "axum 0.7.9", + "bytes", + "chrono", + "futures-channel", + "futures-util", + "http 1.3.1", + "http-body 1.0.1", + "js-sys", + "matchit 0.7.3", + "pin-project", + "serde", + "serde-wasm-bindgen 0.6.5", + "serde_json", + "serde_urlencoded", + "tokio", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", + "worker-kv", + "worker-macros", + "worker-sys", +] + +[[package]] +name = "worker-kv" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f06d4d1416a9f8346ee9123b0d9a11b3cfa38e6cfb5a139698017d1597c4d41" +dependencies = [ + "js-sys", + "serde", + "serde-wasm-bindgen 0.5.0", + "serde_json", + "thiserror 1.0.69", + "wasm-bindgen", + "wasm-bindgen-futures", +] + +[[package]] +name = "worker-macros" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d625c24570ba9207a2617476013335f28a95cbe513e59bb814ffba092a18058" +dependencies = [ + "async-trait", + "proc-macro2", + "quote", + "syn 2.0.101", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-macro-support", + "worker-sys", +] + +[[package]] +name = "worker-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34563340d41016b4381257c5a16b0d2bc590dbe00500ecfbebcaa16f5f85ce90" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "writeable" version = "0.5.5" diff --git a/examples/fullstack-wasm/Cargo.toml b/examples/fullstack-wasm/Cargo.toml index 5f95b63303..3e3c72f173 100644 --- a/examples/fullstack-wasm/Cargo.toml +++ b/examples/fullstack-wasm/Cargo.toml @@ -1,8 +1,14 @@ [package] name = "fullstack-wasm" -edition = "2024" +edition = "2021" version.workspace = true +[lib] +crate-type = ["cdylib", "rlib"] + +[package.metadata.wasm-pack.profile.release] +wasm-opt = false + [features] web = ["dioxus/web"] server = ["dioxus/server-core"] @@ -11,3 +17,9 @@ server = ["dioxus/server-core"] dioxus = { workspace = true, features = [ "fullstack", ] } +worker = { version = "0.5.0", features = ["http", "axum"] } +console_error_panic_hook = { version = "0.1.1" } +axum = { version = "0.8", default-features = false, features = ["http1", "http2", "json"] } +tower-service = "0.3.2" + +wasm-bindgen = { workspace = true } diff --git a/examples/fullstack-wasm/dummy/.gitkeep b/examples/fullstack-wasm/dummy/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/fullstack-wasm/src/lib.rs b/examples/fullstack-wasm/src/lib.rs new file mode 100644 index 0000000000..caf11c629a --- /dev/null +++ b/examples/fullstack-wasm/src/lib.rs @@ -0,0 +1,49 @@ +use dioxus::prelude::*; +use worker::{Context, Env, HttpRequest, event}; +use wasm_bindgen::prelude::*; + +// https://github.com/rustwasm/wasm-bindgen/issues/4446#issuecomment-2729543167 +#[cfg(target_family = "wasm")] +mod wasm_workaround { + extern "C" { + pub(super) fn __wasm_call_ctors(); + } +} + +// https://github.com/rustwasm/wasm-bindgen/issues/4446#issuecomment-2729543167 +#[wasm_bindgen(start)] +fn start() { + + // fix: + // freestyle::block::_::__ctor::h5e2299a836106c67:: Read a negative address value from the stack. Did we run out of memory? + #[cfg(target_family = "wasm")] + unsafe { wasm_workaround::__wasm_call_ctors()}; +} + +#[cfg(not(feature = "web"))] +#[event(fetch)] +async fn fetch( + req: HttpRequest, + _env: Env, + _ctx: Context, +) -> worker::Result> { + use axum::Router; + use tower_service::Service; + console_error_panic_hook::set_once(); + let mut router = + Router::new().serve_api_application(ServeConfig::builder().build().unwrap(), app); + Ok(router.call(req).await?) +} + +#[server] +async fn hello_world() -> Result { + Ok("Hello, world!".to_string()) +} + +pub fn app() -> Element { + let hello_world = use_server_future(hello_world)?; + let hello_world = hello_world().unwrap().unwrap(); + rsx! { + "{hello_world}" + } +} diff --git a/examples/fullstack-wasm/src/main.rs b/examples/fullstack-wasm/src/main.rs index 0a37392b30..b693c5917c 100644 --- a/examples/fullstack-wasm/src/main.rs +++ b/examples/fullstack-wasm/src/main.rs @@ -1,18 +1,6 @@ +#[cfg(feature = "web")] use dioxus::prelude::*; fn main() { - dioxus::launch(app); -} - -#[server] -async fn hello_world() -> Result { - Ok("Hello, world!".to_string()) -} - -fn app() -> Element { - let hello_world = use_server_future(hello_world)?; - let hello_world = hello_world().unwrap().unwrap(); - rsx! { - "Hello, world! {hello_world}" - } + dioxus::launch(fullstack_wasm::app); } diff --git a/examples/fullstack-wasm/wrangler.toml b/examples/fullstack-wasm/wrangler.toml new file mode 100644 index 0000000000..b77240ea27 --- /dev/null +++ b/examples/fullstack-wasm/wrangler.toml @@ -0,0 +1,8 @@ +name = "cf-worker" +main = "build/worker/shim.mjs" +compatibility_date = "2025-06-08" + +[build] +command = "dx build --release --platform web --features web --target wasm32-unknown-unknown && cargo install -q worker-build && worker-build --features server" +# without this, wrangler infinitely rebuilds the worker though nothing changed +watch_dir = ["dummy"] diff --git a/packages/fullstack/Cargo.toml b/packages/fullstack/Cargo.toml index b2cc5d6e6c..6b83ede650 100644 --- a/packages/fullstack/Cargo.toml +++ b/packages/fullstack/Cargo.toml @@ -97,6 +97,7 @@ server = [ server-core = [ "server_fn/axum-no-default", "dioxus_server_macro/axum", + "server_fn/axum-no-default", "server_fn/reqwest-no-ws", "server_fn/ssr", "dioxus_server_macro/reqwest", diff --git a/packages/fullstack/src/lib.rs b/packages/fullstack/src/lib.rs index 05a2c6aa17..9749237761 100644 --- a/packages/fullstack/src/lib.rs +++ b/packages/fullstack/src/lib.rs @@ -10,7 +10,7 @@ mod web; #[cfg(all(feature = "web", feature = "document"))] pub use web::FullstackWebDocument; -#[cfg(feature = "server")] +#[cfg(feature = "server-core")] pub use dioxus_server::*; /// A prelude of commonly used items in dioxus-fullstack. @@ -20,6 +20,6 @@ pub mod prelude { pub use dioxus_server_macro::*; pub use server_fn::{self, ServerFn as _, ServerFnError}; - #[cfg(feature = "server")] + #[cfg(feature = "server-core")] pub use dioxus_server::prelude::*; } diff --git a/packages/server/Cargo.toml b/packages/server/Cargo.toml index 487b765150..fc571a2372 100644 --- a/packages/server/Cargo.toml +++ b/packages/server/Cargo.toml @@ -73,6 +73,8 @@ dashmap = "6.1.0" [target.'cfg(target_arch = "wasm32")'.dependencies] tokio = { workspace = true, features = ["rt", "sync", "macros"] } +wasm-bindgen-futures = "0.4" +futures-executor = "0.3" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { workspace = true, features = ["rt", "sync", "rt-multi-thread", "macros", "net"] } diff --git a/packages/server/src/config.rs b/packages/server/src/config.rs index 4a6fdfc37b..ea651430ee 100644 --- a/packages/server/src/config.rs +++ b/packages/server/src/config.rs @@ -403,11 +403,22 @@ pub(crate) fn public_path() -> PathBuf { } // The CLI always bundles static assets into the exe/public directory - std::env::current_exe() - .expect("Failed to get current executable path") - .parent() - .unwrap() - .join("public") + // On WASM targets, current_exe() is not supported, so fallback to a default path + #[cfg(not(target_arch = "wasm32"))] + { + std::env::current_exe() + .expect("Failed to get current executable path") + .parent() + .unwrap() + .join("public") + } + + #[cfg(target_arch = "wasm32")] + { + // For WASM targets (like Cloudflare Workers), use a default public path + // This should typically be set via DIOXUS_PUBLIC_PATH environment variable + PathBuf::from("public") + } } /// An error that can occur when loading the index.html file diff --git a/packages/server/src/render.rs b/packages/server/src/render.rs index 1fbaf5e0cf..c88d2c599e 100644 --- a/packages/server/src/render.rs +++ b/packages/server/src/render.rs @@ -26,8 +26,33 @@ struct PendingSuspenseBoundary { children: Vec, } -/// Spawn a task in the background. If wasm is enabled, this will use the single threaded tokio runtime -fn spawn_platform(f: impl FnOnce() -> Fut + Send + 'static) -> JoinHandle +// Define a platform-specific task handle type +#[cfg(not(target_arch = "wasm32"))] +type PlatformTaskHandle = JoinHandle; + +#[cfg(target_arch = "wasm32")] +type PlatformTaskHandle = WasmTaskHandle; + +#[cfg(target_arch = "wasm32")] +struct WasmTaskHandle { + _phantom: std::marker::PhantomData, +} + +#[cfg(target_arch = "wasm32")] +impl WasmTaskHandle { + fn new() -> Self { + Self { + _phantom: std::marker::PhantomData, + } + } + + fn abort(&self) { + // No-op for WASM since tasks run to completion + } +} + +/// Spawn a task in the background. If wasm is enabled, this will spawn using wasm_bindgen_futures +fn spawn_platform(f: impl FnOnce() -> Fut + Send + 'static) -> PlatformTaskHandle where Fut: Future + 'static, Fut::Output: Send + 'static, @@ -47,7 +72,13 @@ where } #[cfg(target_arch = "wasm32")] { - tokio::task::spawn_local(f()) + // For WASM, spawn the task using wasm_bindgen_futures + wasm_bindgen_futures::spawn_local(async move { + f().await; + }); + + // Return a dummy handle since WASM tasks run to completion + WasmTaskHandle::new() } } @@ -131,7 +162,7 @@ impl SsrRendererPool { receiver: futures_channel::mpsc::Receiver< Result, >, - cancel_task: Option>, + cancel_task: Option>, } impl Stream for ReceiverWithDrop { From 5d3abb4e00741f713bfa20e5909c2285c5b11b0c Mon Sep 17 00:00:00 2001 From: Ryo Hirayama Date: Tue, 10 Jun 2025 22:33:58 +0900 Subject: [PATCH 3/3] npx wrangler dev works but everything wrong --- Cargo.lock | 31 +++++++++------------------ Cargo.toml | 2 +- examples/fullstack-wasm/Cargo.toml | 3 ++- examples/fullstack-wasm/wrangler.toml | 3 ++- packages/dioxus/Cargo.toml | 4 ++-- packages/fullstack/Cargo.toml | 28 +++++++++++++----------- 6 files changed, 32 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index de6ce9b388..23ee989d07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4642,7 +4642,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "server_fn_macro 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "server_fn_macro", "syn 2.0.101", "tower-http", ] @@ -12439,9 +12439,9 @@ dependencies = [ [[package]] name = "serde_qs" -version = "0.15.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3faaf9e727533a19351a43cc5a8de957372163c7d35cc48c90b75cdda13c352" +checksum = "8b417bedc008acbdf6d6b4bc482d29859924114bbe2650b7921fb68a261d0aa6" dependencies = [ "percent-encoding", "serde", @@ -12526,7 +12526,8 @@ dependencies = [ [[package]] name = "server_fn" version = "0.8.2" -source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#cae23e008e71b44a94c20f05d4581259c2dba9c5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b0f92b9d3a62c73f238ac21f7a09f15bad335a9d1651514d9da80d2eaf8d4c" dependencies = [ "axum 0.8.4", "base64 0.22.1", @@ -12580,26 +12581,13 @@ dependencies = [ "xxhash-rust", ] -[[package]] -name = "server_fn_macro" -version = "0.8.2" -source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#cae23e008e71b44a94c20f05d4581259c2dba9c5" -dependencies = [ - "const_format", - "convert_case 0.8.0", - "proc-macro2", - "quote", - "rustc_version", - "syn 2.0.101", - "xxhash-rust", -] - [[package]] name = "server_fn_macro_default" version = "0.8.2" -source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#cae23e008e71b44a94c20f05d4581259c2dba9c5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5ab934f581482a66da82f2b57b15390ad67c9ab85bd9a6c54bb65060fb1380" dependencies = [ - "server_fn_macro 0.8.2 (git+https://github.com/ryo33/leptos.git?branch=test-ws2)", + "server_fn_macro", "syn 2.0.101", ] @@ -14597,7 +14585,8 @@ dependencies = [ [[package]] name = "throw_error" version = "0.3.0" -source = "git+https://github.com/ryo33/leptos.git?branch=test-ws2#cae23e008e71b44a94c20f05d4581259c2dba9c5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41e42a6afdde94f3e656fae18f837cb9bbe500a5ac5de325b09f3ec05b9c28e3" dependencies = [ "pin-project-lite", ] diff --git a/Cargo.toml b/Cargo.toml index 7e0eb9f24d..c2070c5c02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -231,7 +231,7 @@ lru = "0.13.0" async-trait = "0.1.87" axum = { version = "0.8.1", default-features = false } axum-server = { version = "0.7.1", default-features = false } -server_fn = { git = "https://github.com/ryo33/leptos.git", branch = "test-ws2", default-features = false } +server_fn = { version = "0.8.2", default-features = false } server_fn_macro = { version = "0.8.2" } tower = "0.5.2" http = "1.2.0" diff --git a/examples/fullstack-wasm/Cargo.toml b/examples/fullstack-wasm/Cargo.toml index 3e3c72f173..d0bf65c4f3 100644 --- a/examples/fullstack-wasm/Cargo.toml +++ b/examples/fullstack-wasm/Cargo.toml @@ -11,7 +11,8 @@ wasm-opt = false [features] web = ["dioxus/web"] -server = ["dioxus/server-core"] +server-wasm = ["dioxus/server-wasm"] +server = ["dioxus/server"] [dependencies] dioxus = { workspace = true, features = [ diff --git a/examples/fullstack-wasm/wrangler.toml b/examples/fullstack-wasm/wrangler.toml index b77240ea27..7bf837269f 100644 --- a/examples/fullstack-wasm/wrangler.toml +++ b/examples/fullstack-wasm/wrangler.toml @@ -3,6 +3,7 @@ main = "build/worker/shim.mjs" compatibility_date = "2025-06-08" [build] -command = "dx build --release --platform web --features web --target wasm32-unknown-unknown && cargo install -q worker-build && worker-build --features server" +command = "cargo build --release --target wasm32-unknown-unknown --features web && cargo install -q worker-build && worker-build --features server-wasm" +# command = "dx build --release --target wasm32-unknown-unknown --platform web --features web && cargo install -q worker-build && worker-build --features server-wasm" # without this, wrangler infinitely rebuilds the worker though nothing changed watch_dir = ["dummy"] diff --git a/packages/dioxus/Cargo.toml b/packages/dioxus/Cargo.toml index 81644a39c8..91bf0e5216 100644 --- a/packages/dioxus/Cargo.toml +++ b/packages/dioxus/Cargo.toml @@ -100,14 +100,14 @@ server = [ "dioxus-liveview?/axum", "dioxus-fullstack?/server", ] -server-core = [ +server-wasm = [ "dep:dioxus-server", "dep:dioxus_server_macro", "dioxus_server_macro/server", "dioxus_server_macro/axum", "ssr", "dioxus-liveview?/axum", - "dioxus-fullstack?/server-core", + "dioxus-fullstack?/server-wasm", ] # This feature just disables the no-renderer-enabled warning diff --git a/packages/fullstack/Cargo.toml b/packages/fullstack/Cargo.toml index 6b83ede650..0696f9a9bc 100644 --- a/packages/fullstack/Cargo.toml +++ b/packages/fullstack/Cargo.toml @@ -89,21 +89,23 @@ mobile = ["server_fn/reqwest", "dioxus_server_macro/reqwest"] default-tls = ["server_fn/default-tls"] rustls = ["server_fn/rustls", "dep:rustls", "dep:hyper-rustls"] server = [ - "server-core" , - "default-tls", - "server_fn/axum", - "server_fn/reqwest", + "server-core" , + "default-tls", + "server_fn/axum", + "server_fn/reqwest", + "dioxus_server_macro/reqwest", +] +server-wasm = [ + "server-core", + "server_fn/browser", ] server-core = [ - "server_fn/axum-no-default", - "dioxus_server_macro/axum", - "server_fn/axum-no-default", - "server_fn/reqwest-no-ws", - "server_fn/ssr", - "dioxus_server_macro/reqwest", - "dioxus-fullstack-hooks/server", - "dep:dioxus-server", - "dioxus-interpreter-js", + "server_fn/axum-no-default", + "dioxus_server_macro/axum", + "server_fn/ssr", + "dioxus-fullstack-hooks/server", + "dep:dioxus-server", + "dioxus-interpreter-js", ] aws-lc-rs = ["dep:aws-lc-rs"]