React SSR
Official sources are open to Staxis GitLab group members: how to join and view the code.
Repository:
React development
Versions:
tags
and releases
Description
The react pack builds and serves React pages with server-side rendering and browser hydration. Its manifest.label is react and its manifest.typology is viewengine. The runtime engine stays in system-lrpcks/react; application JSX belongs in server-react. At startup, esbuild generates SSR modules in server-side and browser bundles in server-public.
The server selects a page, prepares its props, and renders the initial HTML. The browser then loads the corresponding page bundle and hydrates that HTML to activate React interactions. The current SSR implementation renders a complete HTML string; the streaming code in app-server.jsx is commented out. This pack is a view-engine alternative to EJS or htmlExpress.
Read before flight
-
We suggest keeping server-react and server-side outside every public static root. Reserve the SSR output directory for generated files: the builder clears it before rebuilding. Treat browser bundles as public code, and inspect what your release emits.
-
We suggest returning only browser-safe, JSON-serializable props from ServerPage. Request headers are removed from request.headers before rendering and serialization; values copied elsewhere are still public. Keep credentials and private service objects out of props.
-
We suggest keeping the initial UI deterministic between SSR and hydration. ClientPage runs in both environments. Put browser-only effects in components and keep window, document, and other browser-only operations out of the server render path.
-
We suggest placing authentication and private-route authorization before page rendering. Set a response cache policy appropriate to user-dependent pages; the renderer does not set Cache-Control itself. A backoffice source directory does not provide access control. Verify both the initial HTML response and browser interactions after rebuilding.
Requirements and Installation
The manifest requires serverApp and httpStatics. Install the pack through the Manager:
manager -> install -> react
The npm packages are react, react-dom, and esbuild. Names such as react-dom/server, react-dom/client, and react/jsx-runtime are import subpaths, not separate npm packages. If your installation profile has not installed the dependencies, run:
npm install react react-dom esbuild
Keep React and React DOM on compatible versions. Place serverApp and httpStatics before react, with request checks and authorization ahead of private page handling. Prepare the application before httpListener. The supplied serverApp manifest already permits react. Prepare KEY:VIEWENGINE, the project Vault keys, and integrity records. Page handling is automatic; the pack's manifest declares permits=false and publishes status rather than a consumer render API.
Files Map
| File | Purpose |
|---|---|
| system-lrpcks/react/main.js | Scans JSX pages, builds server/client artifacts, creates the route map, and registers rendering |
| system-lrpcks/react/configs.js | Supplies dependency and path rules, watcher settings, and rendering defaults |
| system-lrpcks/react/manifest.json | Declares label react, typology viewengine, version, and required packs |
| system-lrpcks/react/app/app-server.jsx | Selects the SSR page, runs ServerPage and ClientPage, and creates HTML plus hydration props |
| system-lrpcks/react/app/app-client.jsx | Loads the browser page bundle and calls hydrateRoot |
| system-lrpcks/react/app/application.jsx | Shared document shell for the server and browser |
| server-react/frontoffice/index.jsx, about.jsx | Editable main and secondary page examples |
| server-react/frontoffice/test.jsx | Supplied checks for state, effects, forms, shared UI, query data, and dynamic imports |
| server-react/backoffice/index.jsx | Editable backoffice example, separate from frontoffice |
| server-react/resources/ | Shared UI modules and components; excluded from page-entry scanning by default |
| server-side/ | Generated SSR entry and page bundles |
| server-public/ | Generated browser bootstrap, page entries, shared chunks, and intentionally public static assets |
| README.md | Original pack reference and page-authoring examples |
Configuration
In config.js, React options belong to config.serveropt.templating.react. The enable switch belongs to config.serveropt.templating.enabled, the public root to config.serveropt.folders.public, and Guardian and watcher settings to config.engineopt. Merge these branches into the exported config object, preserving the other packs' rules. The example explicitly supplies the public folder normally configured by httpStatics.
// config.js -> config (merge into the exported object)
engineopt: {
guard: {
allowBareDeps: true,
allowedDeps: [{
pack: 'react',
roots: ['react', 'server-react', 'server-side'],
require: ['react', 'react-dom/server', 'react-dom/client', 'react/jsx-runtime', 'esbuild']
}],
allowedImports: [{
pack: 'react',
files: ['./server-react/*', './server-side/*', './server-public/*', './system-lrpcks/react/*']
}],
allowedExceptions: [
'./system-lrpcks/react/app/app-client.jsx',
'./server-public/reactapp-public.js'
],
allowedFileAccess: [{
pack: 'react',
roots: [
'./server-react', './server-react/*',
'./server-side', './server-side/*',
'./server-public', './server-public/*'
]
}]
},
watching: ['server-react'],
watchingDeny: ['server-public', 'server-side']
},
serveropt: {
folders: {
public: 'server-public'
},
templating: {
enabled: true,
react: {
ssrFoldername: 'server-side',
editFoldername: 'server-react',
publicFilename: 'reactapp-public',
serverFilename: 'reactapp-server-side',
runtimebuild: false,
compression: false,
unmap: ['resources'],
external: []
},
exlude: ['*server-react*']
},
notKindness: []
}
allowBareDeps is a global setting; allowedDeps still declares the allowed dependency names. The client bootstrap contains a browser dynamic import, so the supplied source and generated bootstrap paths are listed in allowedExceptions. If publicFilename changes, update the generated path there too. If you move the source, SSR, public, or pack roots, update the matching import, file-access, exception, and watcher paths.
| Option under config.serveropt.templating.react | Behaviour |
|---|---|
| editFoldername | Editable JSX source root |
| ssrFoldername | Generated SSR root, cleared before rebuilding |
| publicFilename | Main browser bundle name without .js |
| serverFilename | Main SSR bundle name without .js |
| runtimebuild=false | Required current setting; in-memory runtime builds are not implemented |
| compression | Selects build minification behaviour, described below |
| unmap | Directory basenames skipped when scanning route entries; defaults to resources |
| external | Additional module names left external in the server builds; not a browser dependency loader |
The spelling exlude is retained in the shared templating branch. It is not an enforced React route-denial mechanism in the current implementation. Do not use it as an access-control rule. Use the configured page map and request middleware for routing and authorization.
Editable Sources and Generated Outputs
project-root/
βββ system-lrpcks/react/ # engine and shared SSR/client shell
βββ server-react/ # edit application JSX here
β βββ frontoffice/
β β βββ index.jsx
β β βββ about.jsx
β β βββ test.jsx
β βββ backoffice/
β β βββ index.jsx
β βββ resources/
β βββ uicollection.jsx
β βββ components/
βββ server-side/ # generated server output
β βββ reactapp-server-side.js
β βββ frontoffice/index.js
β βββ backoffice/index.js
βββ server-public/ # generated browser output and public assets
βββ reactapp-public.js
βββ frontoffice/index.js
βββ backoffice/index.js
βββ resources/
βββ reactitems-...js
βββ styles.css
βββ hellodev.webp
The layer builds when it attaches. It creates temporary server/client entry wrappers, builds the SSR renderer and page modules, builds browser entries with shared chunks, then removes the temporary wrappers. The browser build uses ES modules with an ES2022 target. The source tree itself is not copied into the public root. Edit server-react and rebuild; do not maintain application changes in generated JavaScript. The shipped CSS and image are already public files and remain the responsibility of static delivery.
A module imported by ClientPage can still become browser code even when its directory is excluded from route scanning. unmap makes resources a shared non-route area, not a private-code boundary. Source and generated application files are outside the react pack directory, so that pack's own HMAC snapshot does not cover them. Review the complete application release.
Write a Page with Server Data and an Interactive Component
Save this as server-react/frontoffice/index.jsx. Export both ServerPage and ClientPage: the current generated wrappers re-export both names. When no server preparation is needed, ServerPage can simply return props unchanged.
import { useState } from 'react'
export const ServerPage = async props => {
return {
...props,
text: 'Hello from the server'
}
}
export const ClientPage = async props => {
const { UiButton } = await import('../resources/uicollection.jsx')
function Counter() {
const [count, setCount] = useState(0)
return (
<UiButton onClick={() => setCount(current => current + 1)}>
Count: {count}
</UiButton>
)
}
const Head = () => (
<>
<title>React on Staxis</title>
<link rel="stylesheet" href="/resources/styles.css" />
</>
)
const Body = () => (
<>
<h1>React is running</h1>
<p>{props.text}</p>
<Counter />
<p><a href="/about">About</a></p>
<p><a href="/backoffice/">Backoffice</a></p>
</>
)
return { Lang: 'en', Head, Body }
}
The shared UI collection is supplied in server-react/resources/uicollection.jsx and exports UiButton, UiPanel, UiPill, and UiBoxScroll. Importing it inside ClientPage follows the pack README. The counter's hook runs inside a React component, not directly in the ClientPage factory. The server emits its initial Count: 0 markup; the button becomes interactive after hydration.
ServerPage runs on the server before rendering. ClientPage is a page factory used on both the server and browser: it returns Lang and the Head and Body component functions. The shared document shell creates html, head, and body, so Head and Body should return their contents rather than another complete document. Preserve the routing information in props.react when returning server data.
Add Another Route
Create server-react/frontoffice/about.jsx with the same two exports:
export const ServerPage = async props => props
export const ClientPage = props => {
const Head = () => <title>About</title>
const Body = () => (
<>
<h1>About this application</h1>
<a href="/">Home</a>
</>
)
return { Lang: 'en', Head, Body }
}
Use .jsx page names made from letters, digits, and underscores. The scanner treats eligible JSX files outside unmap directories as route entries. Keep shared components in resources, so they are imported by pages rather than built as standalone routes. Ordinary links request another server-rendered page; the pack does not install a client-side navigation router.
| Requested Path | Editable Page |
|---|---|
| / or /index | server-react/frontoffice/index.jsx |
| /about | server-react/frontoffice/about.jsx |
| /test | server-react/frontoffice/test.jsx |
| /backoffice/ or /backoffice/index | server-react/backoffice/index.jsx |
| /backoffice | No automatic redirect to /backoffice/ |
| /resources/... or an unmapped page | Not a React route entry; static files or later handlers can respond |
frontoffice is removed from the public route prefix by the current renderer. Backoffice remains a separate sibling namespace. A trailing slash selects index for that directory. Route matching accepts a restricted path character set and rejects extension-bearing paths; generated .js files are delivered by httpStatics. A React route miss sets status 404 and continues to the next handler.
Request Data and the Browser Boundary
| Property supplied to ServerPage | Meaning |
|---|---|
| props.request.url | Original request URL, including its query string |
| props.request.method | HTTP method |
| props.request.headers | Request headers, available only before the renderer removes this property |
| props.request.query | Parsed query values; repeated keys become arrays |
| props.react.path | Normalized path used for page selection |
| props.react.routing | Matched public route |
| props.react.pagebundle | Generated browser entry URL for this page |
| props.react.clientbundle | Main browser bootstrap name |
After ServerPage returns, the renderer removes props.request.headers before calling ClientPage, creating the HTML, and serializing props into the reactprops JSON script. It does not remove sensitive values that your code copies into other fields. Return plain browser-safe data and retain props.react; the bootstrap uses pagebundle to load the correct generated ClientPage.
The browser reads those props, imports the generated page module, calls ClientPage, removes the carrier nodes, and hydrates the document using the shared application shell. Both the HTML and serialized props are observable by the user. Keep the first browser render consistent with SSR, then use effects or events for browser-only updates. See React's hydration reference.
Build, Launch, and Check the Result
node project start
curl -i http://127.0.0.1:3000/
curl -i "http://127.0.0.1:3000/test?mode=alpha"
curl -i http://127.0.0.1:3000/backoffice/
Run the start command in the project directory and perform the HTTP checks from another terminal. Adjust the address to your listener. Build errors appear in Staxis logs; check the rendered page and generated files before treating the application as ready. Successful React responses use status 200 and text/html; charset=utf-8. Rendering errors are logged, set status 500 when possible, and continue to later middleware for response handling.
In a browser, verify that the initial HTML appears, the bootstrap and page bundles load from server-public, and clicking the counter changes its value. The supplied /test page also exercises effects, forms, shared components, query values, and a dynamically loaded component. Its external fetch example depends on the remote endpoint and your browser's network policy.
Watching and Build Options
The supplied engineopt.watching entry observes server-react during local development through the project launcher. Changes restart the process and rebuild the artifacts; this is not React hot module replacement. Keep server-public and server-side in engineopt.watchingDeny to avoid watching generated output. The launcher's watch behaviour depends on its development-mode detection. See Security Profiles for the separate effects of development, fastload, and integrity verification.
runtimebuild must remain false: the current layer writes builds to disk during attach. compression='by-build' enables esbuild minification directly; true also requests minification. An available httpCompression configuration can influence these flags when serveStatic='compressed', including when compression is false or auto. These are build transformations, not gzip transport compression. Inspect the generated code and actual response headers separately.
config.serveropt.notKindness controls bypasses in httpKindness, not React routing. When using that fallback layer, choose patterns matching your API, probe, and download URLs so their responses remain in the intended format. Generated bundle paths, source roots, and cache behaviour must remain aligned across the renderer, static delivery, Guardian, and deployment configuration.
The published assets report status, engine='react', and routing=['jsx']. For the original source layout and examples, consult the pack README.
Documentation
This page is the HTML adaptation of the pack's README.md, with practical clarifications checked against the implementation. Complete Staxis onboarding to request GitLab access to the official sources.