From f430cbac8690de0d4dc55bda6c7da13ebc729340 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Wed, 11 Oct 2023 08:57:21 -0400 Subject: [PATCH 1/4] docs: better document `default` and `wasm` features on `leptos_axum` (closes #1872) --- integrations/axum/src/lib.rs | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index fce9801450..f2a435c8c8 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -1,6 +1,34 @@ #![forbid(unsafe_code)] //! Provides functions to easily integrate Leptos with Axum. //! +//! ## JS Fetch Integration +//! The `leptos_axum` integration supports running in JavaScript-hosted WebAssembly +//! runtimes, e.g., running inside Deno, Cloudflare Workers, or other JS environments. +//! To run in this environment, you need to disable the default feature set and enable +//! the `wasm` feature on `leptos_axum` in your `Cargo.toml`. +//! ```toml +//! leptos_axum = { version = "0.5.1", default-features = false, features = ["wasm"] } +//! ``` +//! +//! ## Features +//! - `default`: supports running in a typical native Tokio/Axum environment +//! - `wasm`: with `default-features = false`, supports running in a JS Fetch-based +//! environment +//! - `nonce`: activates Leptos features that automatically provide a CSP [`Nonce`](leptos::nonce::Nonce) via context +//! - `experimental-islands`: activates Leptos [islands mode](https://leptos-rs.github.io/leptos/islands.html) +//! +//! ### Important Note +//! Prior to 0.5, using `default-features = false` on `leptos_axum` simply did nothing. Now, it actively +//! disables features necessary to support the normal native/Tokio runtime environment we create. This can +//! generate errors like the following, which don’t point to an obvious culprit: +//! ``` +//! `spawn_local` called from outside of a `task::LocalSet` +//! ``` +//! If you are not using the `wasm` feature, do not set `default-features = false` on this package. +//! +//! +//! ## More information +//! //! For more details on how to use the integrations, see the //! [`examples`](https://github.com/leptos-rs/leptos/tree/main/examples) //! directory in the Leptos repository. @@ -204,9 +232,10 @@ macro_rules! spawn_task { let pool_handle = get_leptos_pool(); pool_handle.spawn_pinned(move || { $block }); } else { - // either the `wasm` feature or `default` feature should be enabled - // this is here mostly to suppress unused import warnings etc. - spawn_local($block); + _ = $block; + panic!("It appears you have set `default-features = false` on `leptos_axum`, \ + but are not using the `wasm` feature. Either remove `default-features = false` or, \ + if you are running in a JS-hosted WASM server environment, add the `wasm` feature."); } } }; From 9e4325ed72c8231a6b629944887fde3b1a202b9a Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Wed, 11 Oct 2023 15:08:42 -0400 Subject: [PATCH 2/4] ok, clippy... --- integrations/axum/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index f2a435c8c8..e4a9193982 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -232,10 +232,10 @@ macro_rules! spawn_task { let pool_handle = get_leptos_pool(); pool_handle.spawn_pinned(move || { $block }); } else { - _ = $block; - panic!("It appears you have set `default-features = false` on `leptos_axum`, \ + eprintln!("\n\nIt appears you have set `default-features = false` on `leptos_axum`, \ but are not using the `wasm` feature. Either remove `default-features = false` or, \ - if you are running in a JS-hosted WASM server environment, add the `wasm` feature."); + if you are running in a JS-hosted WASM server environment, add the `wasm` feature.\n\n"); + spawn_local($block); } } }; From 75fbc7bb60bdee2699eb5fe538e7056592c470db Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Fri, 13 Oct 2023 16:28:41 -0400 Subject: [PATCH 3/4] huh --- integrations/axum/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index e4a9193982..030b8b0dde 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -232,9 +232,9 @@ macro_rules! spawn_task { let pool_handle = get_leptos_pool(); pool_handle.spawn_pinned(move || { $block }); } else { - eprintln!("\n\nIt appears you have set `default-features = false` on `leptos_axum`, \ - but are not using the `wasm` feature. Either remove `default-features = false` or, \ - if you are running in a JS-hosted WASM server environment, add the `wasm` feature.\n\n"); + eprintln!("It appears you have set 'default-features = false' on 'leptos_axum', \ + but are not using the 'wasm' feature. Either remove 'default-features = false' or, \ + if you are running in a JS-hosted WASM server environment, add the 'wasm' feature."); spawn_local($block); } } From bdddddbe26ad66082924451f1769e0f3452fcf14 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Thu, 19 Oct 2023 16:34:18 -0400 Subject: [PATCH 4/4] oops --- integrations/axum/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index 030b8b0dde..dc208a92c9 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -21,9 +21,9 @@ //! Prior to 0.5, using `default-features = false` on `leptos_axum` simply did nothing. Now, it actively //! disables features necessary to support the normal native/Tokio runtime environment we create. This can //! generate errors like the following, which don’t point to an obvious culprit: -//! ``` +//! ` //! `spawn_local` called from outside of a `task::LocalSet` -//! ``` +//! ` //! If you are not using the `wasm` feature, do not set `default-features = false` on this package. //! //!