Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 109 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ members = [
"examples/fullstack-desktop",
"examples/fullstack-auth",
"examples/fullstack-websockets",
"examples/fullstack-wasm",

# Playwright tests
"packages/playwright-tests/liveview",
Expand All @@ -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]
Expand Down Expand Up @@ -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" }
Expand Down
26 changes: 26 additions & 0 deletions examples/fullstack-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "fullstack-wasm"
edition = "2021"
version.workspace = true

[lib]
crate-type = ["cdylib", "rlib"]

[package.metadata.wasm-pack.profile.release]
wasm-opt = false

[features]
web = ["dioxus/web"]
server-wasm = ["dioxus/server-wasm"]
server = ["dioxus/server"]

[dependencies]
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 }
5 changes: 5 additions & 0 deletions examples/fullstack-wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Fullstack WASM

```sh
dx build --platform server --target wasm32-unknown-unknown
```
Empty file.
49 changes: 49 additions & 0 deletions examples/fullstack-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<axum::http::Response<axum::body::Body>> {
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<String, ServerFnError> {
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}"
}
}
6 changes: 6 additions & 0 deletions examples/fullstack-wasm/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[cfg(feature = "web")]
use dioxus::prelude::*;

fn main() {
dioxus::launch(fullstack_wasm::app);
}
9 changes: 9 additions & 0 deletions examples/fullstack-wasm/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name = "cf-worker"
main = "build/worker/shim.mjs"
compatibility_date = "2025-06-08"

[build]
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"]
9 changes: 9 additions & 0 deletions packages/dioxus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ server = [
"dioxus-liveview?/axum",
"dioxus-fullstack?/server",
]
server-wasm = [
"dep:dioxus-server",
"dep:dioxus_server_macro",
"dioxus_server_macro/server",
"dioxus_server_macro/axum",
"ssr",
"dioxus-liveview?/axum",
"dioxus-fullstack?/server-wasm",
]

# This feature just disables the no-renderer-enabled warning
third-party-renderer = []
Expand Down
Loading