-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/HEAD' into 0.22-release-changelog
- Loading branch information
Showing
49 changed files
with
349 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Yew SSR Example</title> | ||
|
||
<link data-trunk rel="rust" data-bin="simple_ssr_hydrate" data-cargo-features="hydration" /> | ||
</head> | ||
</html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Yew SSR Example</title> | ||
|
||
<link data-trunk rel="rust" data-bin="simple_ssr_hydrate" data-cargo-features="hydration" /> | ||
</head> | ||
|
||
<body></body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "wasi_ssr_module" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["langyo <langyo.china@gmail.com>"] | ||
|
||
[dependencies] | ||
yew = { path = "../../packages/yew", features = ["ssr"] } | ||
yew-router = { path = "../../packages/yew-router" } | ||
|
||
anyhow = "^1" | ||
bytes = "^1" | ||
serde = { version = "^1", features = ["derive"] } | ||
serde_json = "^1" | ||
lazy_static = "^1" | ||
|
||
tokio = { version = "^1", features = ["macros", "rt", "time"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# WASI SSR Module Example | ||
|
||
This example demonstrates how to use the WASI target to run a simple server-side rendering application. | ||
|
||
It depends on [wasmtime](https://wasmtime.dev)'s WASI preview2. | ||
|
||
## Building | ||
|
||
To build the example, run the following command from the root of the repository: | ||
|
||
```bash | ||
cargo build --manifest-path examples/wasi_ssr_module/Cargo.toml --target wasm32-wasi --release | ||
``` | ||
|
||
## Running | ||
|
||
> Note: This example requires the wasmtime CLI to be installed. See [wasmtime's installation instructions](https://docs.wasmtime.dev/cli-install.html) for more information. | ||
```bash | ||
wasmtime target/wasm32-wasi/release/wasi_ssr_module.wasm | ||
``` | ||
|
||
> Note: If your wasmtime CLI throws an error that it says some imports like `__wbindgen_placeholder__::__wbindgen_xxx` is invalid, try to run `cargo update`. See issue [rustwasm/gloo#411](https://github.com/rustwasm/gloo/pull/411#discussion_r1421219033). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#![allow(unused_imports)] | ||
#![allow(non_snake_case)] | ||
|
||
mod router; | ||
|
||
use anyhow::Result; | ||
use router::{switch, Route}; | ||
use yew::prelude::*; | ||
use yew::LocalServerRenderer; | ||
|
||
#[function_component] | ||
fn Content() -> Html { | ||
use yew_router::prelude::*; | ||
|
||
html! { | ||
<> | ||
<h1>{"Yew WASI SSR demo"}</h1> | ||
<Switch<Route> render={switch} /> | ||
</> | ||
} | ||
} | ||
|
||
#[function_component] | ||
fn App() -> Html { | ||
use yew_router::history::{AnyHistory, History, MemoryHistory}; | ||
use yew_router::prelude::*; | ||
|
||
let history = AnyHistory::from(MemoryHistory::new()); | ||
history.push("/"); | ||
|
||
html! { | ||
<div> | ||
<Router history={history}> | ||
<Content /> | ||
</Router> | ||
</div> | ||
} | ||
} | ||
|
||
pub async fn render() -> Result<String> { | ||
let renderer = LocalServerRenderer::<App>::new(); | ||
let html_raw = renderer.render().await; | ||
|
||
let mut body = String::new(); | ||
body.push_str("<body>"); | ||
body.push_str("<div id='app' style='width: 100vw; height: 100vh; position: fixed;'>"); | ||
body.push_str(&html_raw); | ||
body.push_str("</div>"); | ||
body.push_str("</body>"); | ||
|
||
Ok(body) | ||
} | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() -> Result<()> { | ||
let ret = render().await?; | ||
println!("{}", ret); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use yew::prelude::*; | ||
use yew_router::prelude::*; | ||
|
||
#[derive(Routable, PartialEq, Eq, Clone, Debug)] | ||
pub enum Route { | ||
#[at("/")] | ||
Portal, | ||
|
||
#[at("/t/:id")] | ||
Thread { id: String }, | ||
|
||
#[not_found] | ||
#[at("/404")] | ||
NotFound, | ||
} | ||
|
||
pub fn switch(routes: Route) -> Html { | ||
match routes { | ||
Route::Portal => { | ||
html! { <h1>{"Hello"}</h1> } | ||
} | ||
Route::Thread { id } => { | ||
html! { <h1>{format!("Thread id {}", id)}</h1> } | ||
} | ||
Route::NotFound => { | ||
html! { <h1>{"Not found"}</h1> } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![cfg(not(target_os = "wasi"))] | ||
|
||
use std::time::Duration; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![cfg(not(target_os = "wasi"))] | ||
|
||
use std::time::Duration; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![cfg(not(target_os = "wasi"))] | ||
|
||
use std::time::Duration; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![cfg(not(target_os = "wasi"))] | ||
|
||
use std::sync::atomic::{AtomicU8, Ordering}; | ||
use std::time::Duration; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![cfg(not(target_os = "wasi"))] | ||
|
||
use std::time::Duration; | ||
|
||
use yew::platform::time::sleep; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.