Skip to content

Commit 472b5ff

Browse files
committed
feat: (WIP) SSR support
1 parent 43d9848 commit 472b5ff

File tree

19 files changed

+305
-22
lines changed

19 files changed

+305
-22
lines changed

docs/articles/guide/ssr.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,13 @@ WebAssembly.instantiateStreaming(fetch("/dist/client/app.wasm"), go.importObject
4545
```
4646

4747
This setup delivers an initial server-side render followed by client-side hydration of the Wasm bundle. See `examples/ssr_example` for a working server.
48+
49+
Additional routes in `examples/ssr_example` showcase common patterns:
50+
51+
- `/list` renders a list with `@for`.
52+
- `/layout` demonstrates a layout component using `@slot` and `@include`.
53+
- `/conditional` toggles `@if/@else` blocks based on server-initialized store values.
54+
- `/users` loads data from a JSON file and illustrates multi-page routing.
55+
- A shared sidebar, included via `@include`, links all these demos together for easy navigation.
56+
57+
Templates referenced with `@include` must be registered on the server using `core.RegisterComponent` so the renderer can instantiate them during SSR.

examples/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Examples
2+
3+
- [SSR Example](ssr_example) demonstrates server-side rendering features:
4+
- `/counter` – counter with hydrated store state.
5+
- `/list` – list rendering using `@for`.
6+
- `/layout` – layout component with named slots via `@slot` and `@include`.
7+
- `/conditional``@if/@else` driven by server-initialized store values.
8+
- `/users` – data fetched from JSON with SSR routing across pages.
9+
- all pages share a navigation sidebar included with `@include` for easy exploration.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<root>
2+
@include:sidebar
3+
@if:store:app.default.loggedIn == "true"
4+
<p>Welcome back!</p>
5+
@else
6+
<p>Please log in.</p>
7+
@endif
8+
</root>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
{"name": "Alice", "city": "Rome"},
3+
{"name": "Bob", "city": "Milan"}
4+
]
888 Bytes
Binary file not shown.

examples/ssr_example/home.rtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<root>
2+
@include:sidebar
3+
<h1>SSR Examples</h1>
4+
</root>

examples/ssr_example/index.rtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<root>
2+
@include:sidebar
23
<p>Hello {{name}}</p>
34
<button data-on-click="increment">Increment</button>
45
<p>Count: <span data-store="app.default.count">{{count}}</span></p>

examples/ssr_example/layout.rtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<root>
2+
<header class="p-2 bg-gray-200">@slot:header</header>
3+
<main class="p-4">@slot</main>
4+
</root>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<root>
2+
@include:sidebar
3+
@slot:layout.header
4+
<h1>Layout Example</h1>
5+
@endslot
6+
@slot:layout
7+
<p>Content rendered inside the layout.</p>
8+
@endslot
9+
@include:layout
10+
</root>

examples/ssr_example/list.rtml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<root>
2+
@include:sidebar
3+
<h1>Languages</h1>
4+
<ul>
5+
@for:item in items
6+
<li>@prop:item</li>
7+
@endfor
8+
</ul>
9+
</root>

0 commit comments

Comments
 (0)