ssr + wasm compile warning

This commit is contained in:
Maccesch 2024-05-10 14:15:59 -05:00
parent 41c27c4d97
commit 62754e0d1d
4 changed files with 31 additions and 0 deletions

View file

@ -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 🍕

View file

@ -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"]

17
build.rs Normal file
View file

@ -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."
);
}
}

View file

@ -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