Note: JSR is frozen at 4.5.x. From 5.0.0,
@eserstack/laroux-reactis published on npm under the same name (pnpm add @eserstack/laroux-react); the JSR versions stay available but get no updates.
eserstack Product-Candidate — React integration for laroux · eser/stack Install:
pnpm add @eserstack/laroux-react
React Server Components adapter for laroux.js framework.
This package implements the React Server Components (RSC) protocol for the
laroux.js framework. It provides the necessary adapters and utilities to enable
server-side rendering with React 19.x's Server Components architecture on Node.
Pages in a laroux app use its Link, useRouter and Image exports; the
laroux server and client bootstrap use its RSC protocol and client parser.
Render an image and link to another page from a laroux page:
import * as larouxReact from "@eserstack/laroux-react";
export function HomePage() {
return (
<main>
<larouxReact.Image
src="/images/hero.jpg"
alt="Team at the 2025 offsite"
width={1600}
height={900}
priority
/>
<larouxReact.Link href="/stories">Read the stories</larouxReact.Link>
</main>
);
}- React Server Components: Full support for RSC protocol
- Streaming SSR: Stream React components from server to client
- Client Components: Automatic code splitting for client-side interactivity
- Server Actions: Type-safe server-side mutations
pnpm add @eserstack/laroux-reactThe RSC protocol and client parser are typically used internally by the
laroux commands and @eserstack/laroux-server.
You generally won't need to import them directly unless you're building custom
tooling. Pages and components import Link, useRouter and Image.
Link renders a real <a href> and navigates on the client for internal paths.
The browser handles URLs with a scheme (http(s) on the same origin included,
mailto:, tel: and others) or a leading //, hash links, a target other
than _self, download, clicks with a modifier key or a button other than the
primary one, and clicks whose onClick calls event.preventDefault().
replace swaps the history entry instead of adding one, and scroll={false}
keeps the scroll position. Link navigates on the client in server and client
components alike. laroux drops the functions a server component renders, so the
anchor also carries its options in data-laroux-link and data-laroux-scroll
attributes, and the laroux client script handles clicks on such anchors under
the same rules. useRouter() returns push, replace, back, forward and
refresh for navigation that follows an action:
"use client";
import * as larouxReact from "@eserstack/laroux-react";
export function BackButton() {
const router = larouxReact.useRouter();
return (
<button type="button" onClick={() => router.back()}>
Back
</button>
);
}Image renders an <img> that loads lazily with async decoding. alt is
required (empty for decorative images), and width and height prevent layout
shift. priority loads an above-the-fold image eagerly with
fetchpriority="high", formats={["avif", "webp"]} renders a <picture> with
those variants of the same path, and ImageSizes holds common sizes values.
ResponsiveImage wraps the image in an aspect-ratio box:
import * as larouxReact from "@eserstack/laroux-react";
export function StoryCover(props: { readonly src: string }) {
return (
<larouxReact.ResponsiveImage
src={props.src}
alt=""
aspectRatio="16/9"
sizes={larouxReact.ImageSizes.halfWidth}
fallback="/images/cover-placeholder.jpg"
/>
);
}placeholder="blur" with a blurDataURL shows that small image as the
element's background while the image loads; without a blurDataURL, or with an
empty one, there is no placeholder. ResponsiveImage turns the blur on whenever
blurDataURL is not empty. The prop types (ImageProps,
ResponsiveImageProps, ImageFormat, ObjectFitValue, PlaceholderType,
AspectRatioValue) are exported from the package root.
fallback is shown instead of src when src is empty or fails to load, in
server and client components alike. The image carries it as a
data-laroux-fallback attribute, and the laroux client script swaps it in when
the image fails, including an image that failed before the script loaded.
The client parser lives in the ./client entry point, which the package root
does not re-export:
import * as larouxClient from "@eserstack/laroux-react/client";
// Hydrate client components from RSC stream
const RSCTreeRoot = await larouxClient.createFromFetch(fetch("/rsc"));createFromFetch() resolves to a component function that reads the stream as
React renders it, so parts that have not arrived suspend. When the stream fails,
every part React still waits for fails with the stream's error, and the nearest
error boundary shows it instead of a fallback that never goes away. A stream
that ends without a part fails that part with an error naming it.
createValueFromReadableStream() reads a stream that carries a value instead of
a page tree. The client bootstrap uses it for server action results: it resolves
once the value is complete, and Dates, Maps, Sets, BigInts, undefined and
React elements come back as themselves. Code in a page calls the action itself;
this is for custom tooling that posts to /_rsc:
import * as larouxClient from "@eserstack/laroux-react/client";
const response = await fetch("/_rsc", {
method: "POST",
headers: {
"RSC-Action": "src/app/actions#saveDraft",
"Content-Type": "application/json",
},
body: JSON.stringify(["draft_text"]),
});
if (response.body !== null) {
const result = await larouxClient.createValueFromReadableStream(
response.body,
);
}In the wire format, a string that starts with $ is a reference or a tagged
value (protocol.RSC_VALUE_TAGS), so the laroux server sends strings that start
with $ with a second $ in front, and this parser removes it.
Render @eserstack/streams Span trees as React elements. The same formatting
that produces ANSI terminal output or Markdown can produce React components:
import * as larouxReact from "@eserstack/laroux-react";
import * as streams from "@eserstack/streams";
export function RecipeHeader(props: { readonly name: string }) {
return (
<larouxReact.SpanView>
{[streams.span.bold("Recipe: "), streams.span.cyan(props.name)]}
</larouxReact.SpanView>
);
// Renders: <strong>Recipe: </strong><span class="text-cyan-500" data-color="cyan">name</span>
}Block spans render as HTML elements: a code block as <pre><code>, a table as
<table>, a list as <ul>, a gauge as a <meter> with its percentage, a
separator as <hr> and an alert as a note that names its level in text.
The reactRenderer() renderer implements @eserstack/streams's
Renderer<React.ReactElement> interface — the same interface that ansi(),
markdown(), and plain() implement for strings:
import * as larouxReact from "@eserstack/laroux-react";
import * as streams from "@eserstack/streams";
const renderer = larouxReact.reactRenderer();
const element = renderer.render([
streams.span.bold("hello"),
streams.span.text(" world"),
]);
// <><strong>hello</strong> world</>Use runFunction() to run @eserstack/functions handlers inside React Server
Components. A handler that a CLI command runs can fetch data for a web page
too:
// src/app/routes/posts/[lang]/page.tsx
import * as larouxReact from "@eserstack/laroux-react";
import * as task from "@eserstack/functions/task";
import * as results from "@eserstack/primitives/results";
import * as posts from "../../../../posts.ts";
// Writes progress to ctx.out and returns the data, wherever it runs.
const listPosts = (lang: string) =>
task.task<readonly posts.Post[], Error, larouxReact.FunctionContext>(
async (ctx) => {
ctx.out.writeln(`Listing the ${lang} posts`);
return results.ok(await posts.load(lang));
},
);
type PostsPageProps = { readonly params: { readonly lang: string } };
export async function PostsPage(props: PostsPageProps) {
const items = await larouxReact.runFunction(listPosts(props.params.lang));
return (
<ul>
{items.map((post) => (
<li key={post.slug}>{post.title}</li>
))}
</ul>
);
}runFunction() creates a buffer-backed Output context, runs the handler's Task,
and returns the success value. On failure, it throws — React Error Boundaries
handle the error.
| Export | Purpose |
|---|---|
./mod.ts |
Main: Link, useRouter, Image, ResponsiveImage, SpanView, runFunction |
./client |
Client-side hydration and rendering |
./protocol |
Shared RSC wire protocol utilities |
./span-renderer |
React Span renderer + SpanView component |
./use-function |
runFunction() for running handlers in server components |
./client/bootstrap |
Client bootstrap utilities, including installLinkNavigation() |
react^19.3.0react-dom^19.3.0@eserstack/laroux(navigation, image and router helpers, chunk manifest types)@eserstack/streams(Span types, renderers, Output)@eserstack/functions(Task, handler execution)@eserstack/primitives(Result types)@eserstack/logging(client warnings and errors)
laroux-bundler copies the client bootstrap into the app's dist/ directory and
bundles it from there, so its imports resolve from the app: install react,
react-dom and @eserstack/laroux in the app itself.
This package bridges React's Server Components implementation with the laroux server and integrates with the eser stack handler architecture:
- Server: Renders Server Components to RSC protocol streams
- Client: Hydrates and renders Client Components in the browser
- Protocol: Implements RSC wire format for streaming components
- Span Renderer: Converts
@eserstack/streamsSpan trees to React elements - Function Runner: Runs
@eserstack/functionshandlers inside server components
The client parser and bootstrap log warnings and errors through
@eserstack/logging under the laroux-bundler category. Client builds, in
development and production, replace @eserstack/logging with laroux's browser
logger, which keeps the package's logger API (logger.with(...) included) and
writes warnings and errors to the browser console. The app's browserShims
setting can map @eserstack/logging to another module.
@eserstack/laroux- Framework-agnostic core utilities (navigation, image, router, config)
These changes since 4.5.2 need a change in code, commands or files that use this package. The changelog lists the changes in every package.
-
Server action results arrive as an RSC stream (
text/x-component) instead of JSON, and the client bootstrap accepts only that content type. Deploy laroux-server and laroux-react from the same release. A newer client with an older server fails each call with an error saying to run the same laroux version on both sides. Custom code that read JSON from/_rscdecodes the body instead:import * as larouxClient from "@eserstack/laroux-react/client"; // Before: const result = await response.json(); if (response.body !== null) { const result = await larouxClient.createValueFromReadableStream( response.body, ); }
-
RSC wire format: a string in a J chunk that starts with
$is sent with a second$, values JSON cannot hold travel as tags ($D,$n,$Q,$W,$undefined,$NaN,$Infinity,$-Infinity,$-0; seeprotocol.RSC_VALUE_TAGS), and array children are"$<id>"references. A custom RSC parser strips the extra$and decodes the tags, or uses@eserstack/laroux-react/client. -
createFromReadableStreamandcreateHybridRSCTreefail every pending chunk when the stream fails or ends without it; its Suspense boundary used to wait forever. Render an error boundary above Suspense boundaries that stream data. -
Linkhas noprefetchprop; it was accepted and ignored. Before:<Link href="/about" prefetch>. After:<Link href="/about">. -
Linkruns the app'sonClickon every click before it decides anything, andevent.preventDefault()there stops its client navigation. AnonClickthat assumed a client navigation checksevent.defaultPreventedor the href. Clicks with atargetother than_self, withdownload, or with a non-primary button are left to the browser. -
Linkwritesdata-laroux-link(anddata-laroux-scroll="false"withscroll={false}) on its anchor, and the client bootstrap handles clicks on them, so aLinkthat a server component renders now navigates on the client instead of loading the whole page. Render a plain<a>for a full page load. -
Imagehas noonErrorhandler and nodata-onerrorattribute; it renders the fallback asdata-laroux-fallback, which laroux's client bootstrap applies. An emptysrcwith a fallback renders the fallback directly. A React app that rendersImagewithout laroux's bootstrap adds its own error listener that readsdata-laroux-fallback. -
The client bootstrap that laroux-bundler copies into the build imports
@eserstack/laroux/navigation, and laroux-react no longer depends on laroux-bundler. Add@eserstack/larouxto the app's dependencies. -
Client log records carry their fields as logger properties set with
with(...)instead of anargsattribute. Custom sinks readrecord.propertiesinstead ofrecord.args.
Apache-2.0
Contributions are welcome! Please see the main repository for contribution guidelines.
🔗 For further details, visit the eserstack repository.