diff --git a/CHANGELOG.md b/CHANGELOG.md index ee9c288..de31d32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.10.10] - 2024-05-10 + +### Change 🔥 + +- Added compile-time warning when you use `ssr` feature with `wasm32`. You can enable `wasm_ssr` to remove the warning. + ## [0.10.9] - 2024-04-27 ### Fixes 🍕 diff --git a/Cargo.toml b/Cargo.toml index 2679d07..21308a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -146,6 +146,7 @@ serde = ["dep:serde", "serde_json"] spin = ["dep:leptos-spin", "dep:http1"] ssr = [] msgpack = ["dep:rmp-serde", "dep:serde"] +wasm_ssr = [] [package.metadata.docs.rs] features = ["math", "docs", "ssr", "prost", "serde"] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..7ef2a97 --- /dev/null +++ b/build.rs @@ -0,0 +1,17 @@ +use std::env; + +fn main() { + let ssr = env::var("CARGO_FEATURE_SSR").is_ok(); + let wasm_ssr = env::var("CARGO_FEATURE_WASM_SSR").is_ok(); + let wasm32 = env::var("CARGO_CFG_TARGET_ARCH").expect("should be present in the build script") + == "wasm32"; + if ssr && wasm32 && !wasm_ssr { + println!( + "cargo::warning=You have enabled the `ssr` feature for a wasm32 target. \ +This is probably not what you want. Please check https://leptos-use.rs/server_side_rendering.html \ +for how to use the `ssr` feature correctly.\n \ +If you're building for wasm32 on the server you can enable the `wasm_ssr` feature to get rid of \ +this warning." + ); + } +} diff --git a/docs/book/src/server_side_rendering.md b/docs/book/src/server_side_rendering.md index 6c4cc37..4165b79 100644 --- a/docs/book/src/server_side_rendering.md +++ b/docs/book/src/server_side_rendering.md @@ -54,6 +54,13 @@ By adding `"leptos-use/ssr"` to the `ssr` feature of your project, it will only be enabled when your project is built with `ssr`, and you will get the server functions server-side, and the client functions client-side. +## WASM on the server + +If you enable `ssr` in your project on a `wasm32` target architecture, you will get +a compile-time warning in the console because it is a common mistake that users enable `ssr` globally. +If you're using `wasm32` on the server however you can safely disable this warning by +enabling the `wasm_ssr` feature together with `ssr`. + ## Functions with Target Elements A lot of functions like `use_resize_observer` and `use_element_size` are only useful when a target HTML/SVG element is