Skip to content

Commit

Permalink
Try to support non-browser environments.
Browse files Browse the repository at this point in the history
  • Loading branch information
langyo committed Aug 15, 2024
1 parent 30677e7 commit 1bbb3f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/yew/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 10 additions & 2 deletions packages/yew/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions website/docs/advanced-topics/server-side-rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1bbb3f7

Please sign in to comment.