File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
website/docs/advanced-topics Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,52 @@ fn main() {
195195Example: [ simple_ssr] ( https://github.com/yewstack/yew/tree/master/examples/simple_ssr )
196196Example: [ ssr_router] ( https://github.com/yewstack/yew/tree/master/examples/ssr_router )
197197
198+ ## Single thread mode
199+
200+ Yew supports single thread mode for server-side rendering by ` yew::LocalServerRenderer ` . This mode would work in a single thread environment like WASI.
201+
202+ ``` rust
203+ // Build it by `wasm32-wasi` target
204+
205+ use anyhow :: Result ;
206+ use yew :: {prelude :: * , LocalServerRenderer };
207+
208+ #[function_component]
209+ fn App () -> Html {
210+ use yew_router :: prelude :: * ;
211+
212+ html! {
213+ <>
214+ <h1 >{" Yew WASI SSR demo" }</ h1 >
215+ </ >
216+ }
217+ }
218+
219+ pub async fn render () -> Result <String > {
220+ let renderer = LocalServerRenderer :: <App >:: new ();
221+ let html_raw = renderer . render (). await ;
222+
223+ let mut body = String :: new ();
224+ body . push_str (" <body>" );
225+ body . push_str (" <div id='app'>" );
226+ body . push_str (& html_raw );
227+ body . push_str (" </div>" );
228+ body . push_str (" </body>" );
229+
230+ Ok (body )
231+ }
232+
233+ #[tokio:: main(flavor = " current_thread" )]
234+ async fn main () -> Result <()> {
235+ let ret = render (). await ? ;
236+ println! (" {}" , ret );
237+
238+ Ok (())
239+ }
240+ ```
241+
242+ Example: [ wasi_ssr_module] ( https://github.com/yewstack/yew/tree/master/examples/wasi_ssr_module )
243+
198244::: caution
199245
200246Server-side rendering is currently experimental. If you find a bug, please file
You can’t perform that action at this time.
0 commit comments