diff --git a/packages/yew/Cargo.toml b/packages/yew/Cargo.toml index 78872fb50b3..e200ac93687 100644 --- a/packages/yew/Cargo.toml +++ b/packages/yew/Cargo.toml @@ -32,7 +32,6 @@ html-escape = { version = "0.2.9", optional = true } base64ct = { version = "1.5.0", features = ["std"], optional = true } bincode = { version = "1.3.3", optional = true } serde = { version = "1", features = ["derive"] } -wasm-bindgen-futures = "0.4" [dependencies.web-sys] version = "0.3" @@ -68,6 +67,11 @@ features = [ "HtmlScriptElement", ] +[target.'cfg(target_arch = "wasm32")'.dependencies] + # we move it here so no promise-based spawn_local can present for + # non-wasm32 targets. + wasm-bindgen-futures = "0.4" + [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1.15.0", features = ["rt"], optional = true } diff --git a/packages/yew/src/functional/hooks/use_prepared_state/feat_hydration.rs b/packages/yew/src/functional/hooks/use_prepared_state/feat_hydration.rs index 94770b1b6e4..597c0c4c790 100644 --- a/packages/yew/src/functional/hooks/use_prepared_state/feat_hydration.rs +++ b/packages/yew/src/functional/hooks/use_prepared_state/feat_hydration.rs @@ -3,19 +3,22 @@ use std::marker::PhantomData; use std::rc::Rc; -use gloo_utils::window; -use js_sys::Uint8Array; use serde::de::DeserializeOwned; use serde::Serialize; -use wasm_bindgen::{JsCast, JsValue}; -use wasm_bindgen_futures::JsFuture; +use wasm_bindgen::JsValue; use super::PreparedStateBase; use crate::functional::{use_state, Hook, HookContext}; use crate::io_coop::spawn_local; use crate::suspense::{Suspension, SuspensionResult}; +#[cfg(target_arch = "wasm32")] async fn decode_base64(s: &str) -> Result, JsValue> { + use gloo_utils::window; + use js_sys::Uint8Array; + use wasm_bindgen::JsCast; + use wasm_bindgen_futures::JsFuture; + let fetch_promise = window().fetch_with_str(s); let content_promise = JsFuture::from(fetch_promise) @@ -31,6 +34,11 @@ async fn decode_base64(s: &str) -> Result, JsValue> { Ok(content_array.to_vec()) } +#[cfg(not(target_arch = "wasm32"))] +async fn decode_base64(_s: &str) -> Result, JsValue> { + unreachable!("this function is not callable under non-wasm targets!"); +} + #[doc(hidden)] pub fn use_prepared_state(deps: D) -> impl Hook>>> where