A server-rendered blog written in Rust and transpiled to SolidJS 2.0. The
whole first paint — masthead, post grid, the trending sidebar and the
newsletter — is computed in Node and serialized into index.html, then
hydrated in the browser. It is the SSR counterpart to the client-side
tasks example.
Eight components across nine files in src/:
| File | Component | Demonstrates |
|---|---|---|
src/state.rs |
initial_state |
#[server_state] — an async backend function whose result is serialized into the HTML as window.__SOLID_RS_STATE__ |
src/posts.rs |
load_posts |
a Loader const: an async stand-in for a DB query, awaited by the server state |
src/main.rs |
App |
entry, use_head, a tag-filter create_signal + create_memo, an async memo (`create_memo(async move |
src/featured.rs |
FeaturedPost |
the lead post, a match on the tag, a gradient card, an open callback that routes to the post |
src/post.rs |
PostCard |
a grid card, a match on the tag, a computed chip class, a clickable open callback |
src/post_page.rs |
PostPage |
the article page: the post's body paragraphs in a For, a back button wired to the router |
src/nav_tag.rs |
NavTag |
a filter chip: a computed class={…} for the active state, a target + callback prop, a conditional count badge |
src/trending_list.rs |
TrendingList |
a keyed For over the async memo's resolved list |
src/trending.rs |
trending_now |
a Loader that resolves on a timer, so the SSR build has to wait for it |
src/newsletter.rs |
Newsletter (+ NewsletterLazy) |
lazy! code-splitting, a ref-backed input, guarded subscribe (empty / no-@ rejected with an inline error), a Show swap on subscribe, and a min-w-0/shrink-0 flex row so the button never overflows the card |
src/theme.rs |
Accent, LiveDot |
a module-level const holding a create_context, a provider + use_context |
# from the repo root (build the CLI first)
cargo build -p solid-rs
cd examples/blog
# emit JSX only (no node/npm needed) — prints the generated .jsx
../../target/debug/solid-rs check
# full build (needs Node.js >= 18):
solid-rs install
../../target/debug/solid-rs build # or: solid-rs build
../../target/debug/solid-rs dev # build + serve on :3000, rebuild on changeOpen http://localhost:3000. The build also compiles css/styles.css with
Tailwind into dist/styles.css.
e2e/ssr.mjs loads the prerendered dist/index.html (the point of SSR:
the markup and state were produced by the server bundle in Node), asserts the
posts, the resolved async trending list and the resolved lazy newsletter are
all in the HTML, then hydrates in jsdom and drives the tag filter (rust → 1
post, web → 2, all → 6). It also tags server nodes with an expando and checks
the same node objects survive hydration (claimed, not rebuilt):
solid-rs install
solid-rs build
node e2e/ssr.mjs#[server_state]is the backend entry. It runs only in Node, at build time; it may beasyncand.await(the build'srenderToStreamsettles it before resolving), which is why the post list is in the served HTML. The client reads the same payload back fromwindow.__SOLID_RS_STATE__instead of refetching, so hydration does not flash.- Async lives in a memo, not the body.
create_memo(async move || trending_now().await)throwsNotReadyErroruntil it settles, which suspends the nearest<Loading>boundary. The component body stays a plain sync function, so.awaitbelongs in the closure. lazy!under SSR resumes from the server markup, so it must sit inside a<Loading>boundary: the fallback is what a no-JS client sees until the chunk lands. The e2e proves the split is real by assertingmain.jsdoes not contain the newsletter markup.- Event handlers are zero-arg. The newsletter reads its input through a
ref(the signal setter is the element'sref), and the subscribe handler readsinput().valueon demand. - Tailwind.
css/styles.csspoints@sourceat../src, because the class names live in Rust source, not in a.jsx/.htmlfile Tailwind would scan by default. The serif.mastheadand the.chipare small custom utilities. matchis limited to a few arms, so the tag colour is a 3-armmatchwith a wildcard (the fourth tag falls through to the neutral tone).