From 9fdae79d4a772218f9c91d07081793f557fb9824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E6=AC=A7?= Date: Thu, 22 Aug 2024 15:47:03 +0800 Subject: [PATCH] Limit the function `decode_base64` that it shouldn't runnable in non-browser environment. --- .../hooks/use_prepared_state/feat_hydration.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 b488916a774..77d3650e4e3 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 @@ -12,7 +12,11 @@ use crate::functional::{use_state, Hook, HookContext}; use crate::platform::spawn_local; use crate::suspense::{Suspension, SuspensionResult}; -#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] +#[cfg(all( + target_arch = "wasm32", + not(target_os = "wasi"), + not(feature = "not_browser_env") +))] async fn decode_base64(s: &str) -> Result, JsValue> { use gloo::utils::window; use js_sys::Uint8Array; @@ -34,7 +38,11 @@ async fn decode_base64(s: &str) -> Result, JsValue> { Ok(content_array.to_vec()) } -#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))] +#[cfg(any( + not(target_arch = "wasm32"), + target_os = "wasi", + feature = "not_browser_env" +))] async fn decode_base64(_s: &str) -> Result, JsValue> { unreachable!("this function is not callable under non-wasm targets!"); }