diff --git a/templates/leptos/Cargo.toml b/templates/leptos/Cargo.toml index 39d084b45..2243e47b3 100644 --- a/templates/leptos/Cargo.toml +++ b/templates/leptos/Cargo.toml @@ -23,7 +23,7 @@ leptos_meta = { version = "0.8" } leptos_router = { version = "0.8"{% if use_nightly %}, features = ["nightly"]{% endif %} } tower-service = "0.3" wasm-bindgen = "0.2" -worker = { version = "0.5", features = ["http", "axum", "d1"], optional = true } +worker = { version = "0.6", features = ["http", "axum", "d1"], optional = true } [features] hydrate = ["leptos/hydrate"] @@ -35,6 +35,12 @@ ssr = [ "leptos_router/ssr", ] +[package.metadata.wasm-pack.profile.release] +wasm-opt = false + +[package.metadata.wasm-pack.profile.dev] +wasm-opt = false + [package.metadata.leptos] wasm-validation = false # The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name @@ -95,4 +101,4 @@ lib-features = ["hydrate"] # If the --no-default-features flag should be used when compiling the lib target # # Optional. Defaults to false. -lib-default-features = false \ No newline at end of file +lib-default-features = false diff --git a/templates/leptos/src/lib.rs b/templates/leptos/src/lib.rs index f94040fdd..27a3e039c 100644 --- a/templates/leptos/src/lib.rs +++ b/templates/leptos/src/lib.rs @@ -6,6 +6,26 @@ use crate::app::*; pub mod app; mod components; + +#[cfg(feature = "ssr")] +#[cfg(target_family = "wasm")] +mod wasm_workaround { + unsafe extern "C" { + pub(super) fn __wasm_call_ctors(); + } +} + +#[cfg(feature = "ssr")] +#[wasm_bindgen::prelude::wasm_bindgen(start)] +fn start() { + // Fix for 'Read a negative address value from the stack. Did we run out of memory?'. + // See: https://github.com/cloudflare/workers-rs/issues/772 + #[cfg(target_family = "wasm")] + unsafe { + wasm_workaround::__wasm_call_ctors() + }; +} + #[cfg(feature = "ssr")] pub fn register_server_functions() { use leptos::server_fn::axum::register_explicit;