diff --git a/packages/yew/Cargo.toml b/packages/yew/Cargo.toml index 99faae53629..9efe508fd2a 100644 --- a/packages/yew/Cargo.toml +++ b/packages/yew/Cargo.toml @@ -98,6 +98,7 @@ features = ["ShadowRootInit", "ShadowRootMode", "HtmlButtonElement"] ssr = ["dep:html-escape", "dep:base64ct", "dep:bincode"] csr = [] hydration = ["csr", "dep:bincode"] +not_browser_env = [] default = [] [package.metadata.docs.rs] diff --git a/packages/yew/src/scheduler.rs b/packages/yew/src/scheduler.rs index 4163f960d78..98e82ea0b47 100644 --- a/packages/yew/src/scheduler.rs +++ b/packages/yew/src/scheduler.rs @@ -211,7 +211,11 @@ pub(crate) fn start_now() { }); } -#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] +#[cfg(all( + target_arch = "wasm32", + not(target_os = "wasi"), + not(feature = "not_browser_env") +))] mod arch { use crate::platform::spawn_local; @@ -224,7 +228,11 @@ mod arch { } } -#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))] +#[cfg(any( + not(target_arch = "wasm32"), + target_os = "wasi", + feature = "not_browser_env" +))] mod arch { // Delayed rendering is not very useful in the context of server-side rendering. // There are no event listeners or other high priority events that need to be diff --git a/website/docs/advanced-topics/server-side-rendering.md b/website/docs/advanced-topics/server-side-rendering.md index 07635a0ccdd..046e0149289 100644 --- a/website/docs/advanced-topics/server-side-rendering.md +++ b/website/docs/advanced-topics/server-side-rendering.md @@ -240,6 +240,8 @@ async fn main() { Example: [wasi_ssr_module](https://github.com/yewstack/yew/tree/master/examples/wasi_ssr_module) +> Note: If you are using `wasm32-unknown-unknown` target to build the SSR application, you may need to use feature `not_browser_env` to disable browser-specific features. This would be useful on serverless platforms like Cloudflare Worker. + :::caution Server-side rendering is currently experimental. If you find a bug, please file