Rendering Model
Choose dynamic rendering, static rendering, ISR, or PPR with route-level exports and config.
Rendering controls decide when HTML is produced. Route Runtime separately decides where a dynamic page or API handler executes and how deployment limits are applied.
Dynamic rendering, static rendering, and revalidation apply to every renderer. The component examples below use React-compatible TSX; see Renderers for Preact, Solid, Vue, and Svelte conventions and the features that remain React-specific.
Rendering options
RSC page URLs return HTML for document visits and a Flight payload for requests accepting
text/x-component. Both representations include Vary: Accept. When you enable shared caching,
configure the CDN or reverse proxy to honor Vary; do not cache these responses by URL alone.
Farm.js preserves existing Vary fields, including Origin and Nitro's Accept-Encoding.
| Mode | How to opt in | Best for |
|---|---|---|
| Dynamic | Default for request-bound pages | Dashboards and personalized UI. |
| Static | dynamic = force-static or use static directive | Marketing pages and stable docs. |
| ISR | revalidate = seconds | Content that can refresh on a schedule. |
| PPR | experimental_ppr = true | Static shells with dynamic holes. |
Route-level config
export const dynamic = "force-static";
export const revalidate = 300;
export default async function PricingPage() {
return <main>Pricing</main>;
}Use directives when compactness wins
Farm.js also recognizes compact rendering directives at the top of route modules. This keeps small examples readable while preserving explicit exports for Next-style compatibility.
"use ssg; 60";
export default function BlogPage() {
return <main>Blog</main>;
}use ssg; 60 statically generates the route and revalidates it every 60 seconds. Farm.js also accepts
use ssg, use dynamic, and use ppr; 60 when those rendering modes fit the route.
Dynamic rendering
Use dynamic rendering for request-specific pages such as dashboards, account settings, and pages that depend on cookies, headers, or per-user data.
With experimental React Server Components enabled, Farm.js streams HTML while inserting the styles, hydration payload, and client script. HTML injection preserves UTF-8 bytes across stream chunks, including emoji and non-ASCII content, without buffering the entire page.
export const dynamic = "force-dynamic";
export default async function DashboardPage() {
return <main>Dashboard</main>;
}Static rendering
Use static rendering for pages that can be built once and served quickly.
During a production build, Farm.js also scans routes that use the default dynamic mode. If a non-parameterized route does not read cookies, headers, authentication, search parameters, or middleware request data, Farm.js reports it as a static-rendering candidate. The build keeps the route dynamic until you opt in, because request-bound work may be hidden in an imported component or data loader.
Review each suggestion, including its imported code, then add the static export when it is safe. This keeps personalized pages dynamic while making stable pages easy to move onto the fastest rendering and caching path.
Let the build decide
experimental.staticPages turns that report into a decision, as Next.js makes it: the build renders
each candidate once and writes it as a file only when the render read no request state.
import { defineConfig } from "@farm.js/core";
export default defineConfig({
experimental: {
staticPages: "enabled",
},
});| Mode | Behavior |
|---|---|
"off" | Pages without a rendering mode render on each request. This is the default. |
"analyze" | Renders the candidates and prints the verdicts. Writes no new files. |
"enabled" | Writes the candidates whose render read no request state. |
A page is a candidate when it sets no rendering mode (or sets dynamic = "auto"), lists its params
if it has dynamic segments, and passes the source check above. The build keeps it on the server
without rendering it when middleware, a redirect or rewrite, i18n, a route context, a server plugin,
or a route rule or runtime control applies to its path, or when an intercepting route opens it.
The build-time render then decides:
- A render that reads headers or cookies keeps the page on the server. That includes reads in an
imported helper, an auth helper, the server
apiclient and integration clients, which the source check can't see. The build waits for every Suspense boundary, so a read after anawaitinside one counts too. - A file answers every query string, so a render that reads the query keeps the page on the server
too: the
searchorsearchParamsprops of the page, its slots orgenerateMetadata, read anywhere they're passed.useSearchParams()in an imported component isn't caught yet; give such a pagedynamic = "force-dynamic". - So does a render that answers an error status, throws (in a Suspense boundary too), or gets middleware data. A page that throws logs a warning, and the build carries on.
- Every other candidate is written and served like a
force-staticpage.
↪ Keeping /account server-handled (the render read cookies through a helper, such as an auth or api client)
📄 Prerendered 12 page(s) that read no request state (experimental.staticPages)Data the render fetched stays as built until the next deploy. Export revalidate for a page that
should refresh on a schedule, or dynamic = "force-dynamic" for one that must render on every
request. Start with "analyze" to see which pages would change. farm dev renders every page on
each request in every mode, and the option does nothing on the RSC pipeline
(experimental.serverComponents: { mode: "rsc" }).
If an explicitly static route directly reads request APIs or request props, Farm.js reports the unsafe read and keeps the route dynamic instead of freezing request-specific HTML into a shared artifact. This check covers the route module itself; continue reviewing imported components and data loaders, because request-bound work in transitive imports cannot be proven safe from the route source alone.
Farm.js serves generated HTML only for GET and HEAD requests. Other request methods continue through
the live route instead of receiving a cached page document.
A static page that calls redirect() or permanentRedirect() while it renders has no HTML to save.
The build keeps it server-handled, so each request gets its 307 or 308 with the Location header.
The build prerenders up to eight pages at once, or as many as the machine has CPU cores when that is
fewer. Each page renders as its own request, as it would on the production server, so the output does
not depend on this number. To lower it, for example when pages call a rate-limited API, set Nitro's
prerender.concurrency from a plugin's build.configure
hook.
export const dynamic = "force-static";
export default function AboutPage() {
return <main>About Farm.js</main>;
}A page.md or page.mdx page opts in the same way, with an ESM export at the top level of its
source. Farm.js reads the literal value without evaluating the page, so write a string, number, or
boolean; an export inside a fenced code block is part of the content, not the page's config.
dynamic, revalidate, and ssg are read this way. Pages the
docs engine renders ignore them and follow docs.prerender.
---
title: Installation
---
export const dynamic = "force-static";
# InstallationISR-style revalidation
revalidate caches a static response and refreshes it after the configured number of seconds.
export const dynamic = "force-static";
export const revalidate = 300;
export default async function PricingPage() {
const plans = await loadPlans();
return <PricingTable plans={plans} />;
}In production a page with revalidate is sent with
Cache-Control: public, s-maxage=<revalidate>, stale-while-revalidate=300, so a CDN or reverse
proxy serves it and refreshes it in the background; a static page the server renders on request
gets s-maxage=60. A render that is one visitor's is sent with Cache-Control: private, no-store
instead: a request with a cookie other than Farm.js's deployment cookie or with an Authorization
header, middleware request data, a render that reads the request or suspends, and a response that
middleware let through (see Responses behind middleware). A
Cache-Control that middleware sets with ctx.headers does not replace the page's. Shareable
responses never set the deployment cookie. farm dev renders these pages on each request without
a shared policy. React Server Components apps follow the same rules, except that a page streams
with its policy set up front, as described under React Server Components.
PPR with Suspense
PPR is for pages with a stable shell and dynamic sections. Put dynamic work behind Suspense boundaries so the shell can be cached while the slower section resolves independently.
import { Suspense } from "react";
export const experimental_ppr = true;
export const revalidate = 60;
export default function DashboardPage() {
return (
<main>
<h1>Dashboard</h1>
<Suspense fallback={<RevenueSkeleton />}>
<RevenuePanel />
</Suspense>
</main>
);
}Deferred route islands
The route-level hydration strategy is shared by renderer adapters. Preact uses the same nested
"use client" analysis through its compatibility runtime; Solid, Vue, and Svelte currently hydrate
at the route boundary selected by their adapter.
Client routes and server routes that import a client boundary can defer their JavaScript while Farm.js
keeps the server-rendered HTML visible. Add an optional static island export to the client module:
"use client";
export const island = "interaction";
export function CopyButton({ value }: { value: string }) {
return <button onClick={() => navigator.clipboard.writeText(value)}>Copy</button>;
}Farm.js propagates the strategy to the route hydration boundary, emits it in the route manifest, and splits production route modules behind dynamic imports. Deferred routes therefore avoid evaluating their route chunk until its trigger while preserving the initial SSR output.
These strategies control hydration of the initial server-rendered document. During client-side navigation, the navigation itself signals user intent, so Farm.js loads and renders a route-wide destination immediately instead of leaving the previous route visible while waiting for another trigger.
| Strategy | Hydration trigger |
|---|---|
load | Immediately. The default, except as below in islands mode. |
interaction | The first button-like click or same-page link; replayed after. |
visible | When the route boundary approaches the viewport. |
idle | During browser idle time, with a timeout fallback. |
Until a page hydrates, Farm.js holds clicks on its buttons and its form submissions, and replays them once it has, in development and in production builds. An early submit runs the page's own handler instead of going to the server as a native form post.
With isolated client hydration, each eligible
client module keeps its own strategy, including after SPA navigation. Sibling boundaries can mix
all four strategies: one boundary's trigger never hydrates another, and an interaction click is
claimed and replayed once by the boundary that contains it. Removing a boundary cancels its pending
observer, idle callback, or interaction listener. Islands mode
(serverComponents: { mode: "islands" }) keeps each client module's strategy the same way, and gives
a module without an island export interaction when its code provably does nothing before a
click (React Server Components lists the checks). With
React Server Components ({ mode: "rsc" }), React's client hydrates every client component on load
and the island export has no effect.
Farm.js uses the same isolated boundary metadata for Vite development, streamed or buffered SSR, and statically generated HTML. In development, updating a client module rerenders every live boundary created from that module without importing or replacing its server-owned layout; sibling boundary state stays mounted. If one page needs the route-wide fallback, that fallback stays on the page boundary, and the islands in its server-owned layout stay islands. Farm.js also keeps graphs above four statically bounded islands route-wide. Data-dependent boundary lists use the same fallback because their root count is unknown before streaming. This measured guard prevents request, marker, root, and hydration overhead from growing past the first observed crossover; the benchmark report includes route-wide, isolated, and RSC controls with raw samples. The representative fixtures also run route-wide and isolated hydration with Farm.js's experimental React compiler enabled, proving both the initial hydration cost and repeated state-update cost of the combined path.
The export must be one of these static string literals so Farm.js can analyze it without executing
application code. Without an explicit route-level island export, a route that imports client
boundaries with different strategies safely falls back to load because its current route-level
React-compatible root cannot schedule those children independently. Keep interactive leaves small today; a
eligible leaves can also use Farm.js's experimental React compiler for direct state binding updates
after their independent roots mount.
Async pages and client components
A page or layout can be an async server component and still render "use client" components that
work in the browser:
import { StarButton } from "./star-button";
export default async function RepoPage() {
const repo = await getRepo();
return (
<main>
<h1>{repo.name}</h1>
<StarButton initialCount={repo.stars} />
</main>
);
}React cannot run an async component in the browser, so the page itself stays server-rendered and
never ships to the client. Each eligible client boundary it renders hydrates as its own island, with
the props the server passed it. This works by default in React apps; it does not need
experimental.isolatedClientHydration. The same applies to a page, async or not, that renders an
async server component: that component's client components hydrate as islands too.
Under a parent layout that hydrates as a whole route, such as one that wraps the app in a client
provider, the async page hydrates inside the layout's React tree instead. Farm.js resolves the page on
the server into its elements and client-component references, embeds that tree in the HTML, and the
browser rebuilds it under the layout, so the page's client components read the layout's context and
share its state. Server JSX passed to a client component, as children or any other prop, stays
server output, Suspense
content streams in, and the tree is rebuilt after client navigation between pages of that layout.
A part the server cannot describe this way, such as a server component that calls hooks or a client
component whose props do not serialize, stays server HTML whose own client components hydrate as
islands.
Navigating away cancels pending island work and unmounts its roots without waiting for hydration. React's early-update diagnostic during that synchronous cancellation is expected; hydration mismatches, updates to live roots, and other errors are still reported.
Islands have the same limits as islands without server components:
- Props must be serializable. Server-rendered JSX passed as
childrenor another prop (<ClientShell><ServerList /></ClientShell>) crosses only under a hydrating layout (above); elsewhere that one client component keeps its server HTML and Farm.js logs it once. - A client component must export each component by name (
export function Name,export { Name },export { Name } from "./name", orexport default), not throughexport *. - An integration provider that wraps the whole route, and does not declare
islands: true, keeps its routes route-wide.
When one of these applies, the route stays server-rendered, its client components are not interactive, and Farm.js logs a warning naming the module and the reason. Fix the reason, or render the interactive part from a synchronous page. Preact, Solid, Vue, and Svelte keep async pages server-only.
A client component directly inside <table>, <thead>, <tbody>, <tfoot>, <tr>,
<select>, <optgroup>, <datalist>, <svg>, <ul> or <ol> cannot have an <f-island>
around it: the HTML parser moves or drops it there, and ul > li selectors stop matching. Farm.js
makes the outermost such element the island instead, so the browser gets the same table, options,
SVG shapes and list items as under React Server Components. The element's server-rendered parts
travel as a server tree, so moving "use client" up to a component that renders the whole
element is still the cheaper choice for a large table. Inside a <td>, <th>, <caption>,
<li> or <foreignObject> a client component is an island of its own.
In islands mode every page is a server component, so hydrating a page whole
would ship its module and its server-only imports to the browser. Islands mode never does that:
farm build fails and names each page, the reason, and how to restructure it, and farm dev logs
the same error and serves the page without client JavaScript.
Client components that come from a package, such as the icons in lucide-react, cannot be isolated
yet. An async page renders them as static HTML and still hydrates its own client components as
islands, and Farm.js logs which packages it left static. In islands mode every page does the same, and
so does a layout where each element of the package closes itself and takes no element props, as
icons do. A package component that wraps content, such as a provider, fails the build instead: render
it from a local "use client" module.
Islands without server components
"use client" also remains available in a normal React SSR application. Set
experimental.isolatedClientHydration to "analyze" to audit which local client components Farm.js
can split without changing runtime behavior, or to "enabled" to hydrate them as islands.
Unsupported routes keep the existing route-wide ownership model. See
Isolated client hydration for the modes and safety
rules. This experiment is disabled when RSC owns the route. Integration providers also keep the
route-wide root unless they declare islands: true: that they can be created again around each
island.
React Server Components
Turn on server components in farm.config.ts. Pages and layouts are then server components, and
"use client" marks client components.
import { defineConfig } from "@farm.js/core";
export default defineConfig({
serverComponents: true,
});Before 0.2.0 this key lived under experimental. experimental.serverComponents still works and logs
a deprecation warning; setting both to different engines is an error.
serverComponents: true is the same as serverComponents: { mode: "islands" }, Farm.js's own engine.
It needs no extra packages. To run React's own engine instead, opt out with
serverComponents: { mode: "rsc" }: farm dev, farm build, and farm start then run Farm.js's RSC
pipeline on the official @vitejs/plugin-rsc. When its packages are missing, farm dev and
farm build install them with the app's package manager: @farm.js/plugin at the installed
@farm.js/core version, and @vitejs/plugin-rsc, react, react-dom and
react-server-dom-webpack at the exact versions the plugin requires. Commit the updated
package.json and lockfile. In CI (CI is set) nothing is installed, and the build fails with the
command to run. Set FARM_SKIP_RSC_INSTALL=1 anywhere else the build must not change dependencies.
Fast Refresh works in development without more setup; an app that installs @vitejs/plugin-react
gets its own copy instead of Farm.js's.
Earlier releases read serverComponents: true as { mode: "rsc" }, and an app without the RSC
packages ran without server components. Such an app now runs in islands mode: a component that
uses state, effects, or event handlers needs "use client" (or a parent client component) to
hydrate. Set { mode: "rsc" } to keep React's engine.
Islands mode is Farm.js's own engine
(RFC 0003),
built on islx, its renderer-agnostic wire format:
it renders on Farm.js's normal pipeline, sends static output once as HTML, and hydrates only client
components (how islands mode uses islx, and how it runs
libraries written for RSC). Client components hydrate while the page streams: one above slow Suspense
content is interactive before that content arrives, in farm dev and in production. A client component that receives server output (children, or any element prop) keeps
that output as a slot of the existing HTML instead of receiving it again. Client components inside
that output are its descendants, as in RSC: they read its context (a client provider in a page,
around server content, reaches the consumers in it) and keep their own state, and output it does
not render at first (a tab, a closed panel) is there when it does. useId returns the ids in the
server HTML, unique across client components. A server page under a
layout that hydrates (a client provider, say) hydrates inside that layout's tree, so its client
components read the provider's context. So do a Markdown page's MDX components, and client
components that declare a deferred island strategy: inside the tree they hydrate with the
layout instead of waiting. That layout, and the other server layouts on its pages,
render as server trees too: the browser rebuilds them from the HTML, so their modules and their
server-only imports never reach it, and a navigation keeps the provider's state. A provider
imported straight from a package fails the build; render it from a local "use client" module
(a providers.tsx) instead. A large prop value (512 bytes of JSON or more, such as a
navigation tree) travels once, keyed by its content: client components that share it share one
copy, and a client navigation leaves out the values the browser already holds. A client navigation
also leaves out the layouts the browser keeps: the server renders the page and any layout that
changed, so a layout's client state survives and its HTML is not sent again. A layout the browser
keeps does not render on that navigation, so put access checks in middleware or a page guard,
not in a layout's body. router.refresh() and full loads render every layout. A client
navigation streams too, in production: the browser shows the page with its Suspense fallbacks as
soon as the shell arrives, then each boundary as React completes it, and hydrates the client
components inside. Leaving the page drops the rest of the response. A page under a layout that
hydrates arrives whole. A PPR route caches
each segment under its own key next to the full page, and sends every value so the cached HTML
suits any browser; a prerendered page always sends the whole document. A page under a layout that
hydrates as one root (a client provider around the pages) sends its large prop values once too,
in the payload its client components rebuild from. When the browser already renders that layout,
a navigation to such a page carries only that payload: the browser rebuilds the page in the
layout's React tree, so the server leaves out the page's HTML. "use server"
functions work from forms, with or without JavaScript, and from client components, in farm dev
and in production. A server component can pass one to a client component as a prop, and can
declare one inline: an async function with "use server" as its first statement may read the
component's variables, which travel with it sealed (AES-GCM, bound to the action) rather than as
form fields the browser could read or change. Every instance of one build shares the sealing key;
set ISLX_ACTIONS_KEY to keep forms on open pages working across deploys. A <form> written in a
server component posts its action without a page load once JavaScript runs, and a client
component inside it (a submit button) reads its pending state with useFormStatus from
react-dom: islands mode points that import at islx's, which reports the server form's submit and
is React's anywhere else. A namespace call (ReactDOM.useFormStatus()) reads only a form React
renders. After an
action called from JavaScript, the page refreshes, as the form posted without JavaScript would show
it: islands still on the page keep their state and get their new props, and a redirect() from the
action becomes a client navigation. Props and action arguments are not limited to JSON:
undefined, NaN, Infinity, -0, BigInt, Date, Map, Set, URL, RegExp, typed arrays
and ArrayBuffer arrive as themselves (URL and RegExp in islands mode only; RSC does not
support them). A promise passed unawaited crosses too: the client component reads it with
use() inside a Suspense boundary, works before it settles, and gets the value with its types
when it streams in (a rejection arrives without the server's reason). Functions other than server
actions and class instances do not cross; a client component given one keeps its server HTML and
is not hydrated. A stylesheet that a server page, layout or server component imports (plain CSS or
a CSS module) goes into the app's one stylesheet in production, though the module itself stays on
the server. Islands mode needs none of the RSC packages and is experimental. Both modes share
the authoring rules on this page, so switching between them is a one-line change; the same contract
tests (tests/e2e-server-components) run against both, in development and in production builds.
benchmarks/server-components-payload compares what each mode sends.
In islands mode a page loads React and Farm.js's client runtime when it first needs them. A client
component without an island export waits for a click when its code provably does nothing before
one: it uses no effect, ref, form field, or handler other than onClick and onSubmit (a
handled link only with a # link), and imports nothing but React and the app's own files that
pass the same checks. Copy buttons, like buttons, menu toggles and tables of contents usually
qualify; anything else hydrates at load, and an explicit island export always wins (see
Deferred route islands). A layout that hydrates as one root (a client
provider around the pages) waits the same way when every client component inside it, on the page
too, passes; it hydrates when the pointer reaches one of its links, so the click's navigation
updates it. A page whose client components all wait, or
that has none, starts with a 2.4 KB script, fetches the runtime once the page is idle without
running it, and runs it when one is clicked, pressed or focused, when one that waits for
"visible" or "idle" is due, when the pointer reaches a link, or when a form gets focus. A click
made before then is held and replayed once the component has
hydrated, and a <form> written in a server component posts natively until the runtime runs. An
app with client plugins, a src/client.ts, or docs loads the runtime on every page. On
benchmarks/server-components-payload, with no change to the app, docs, blog, guide and shop
pages run 2.4 KB of JavaScript and fetch 27.6 KB in all ("rsc": 71.0 KB). See
how the two modes compare.
The app's vite options and plugins apply as in other Farm.js apps, and so does built-in Tailwind.
The build goes to the deploy target's
output directory, so farm start and platform deploys work unchanged. On the node target the
build writes gzip copies of its static files, as other Farm.js apps' builds do, and the server sends
them to browsers that accept gzip.
The RSC pipeline (serverComponents: { mode: "rsc" }) does not run every Farm.js feature
yet:
auth,integrations,routeRules,context, andsecurity.cspdecide what a request may see or receive. Running the app without them could expose what they protect, sofarm devandfarm buildstop with an error that names them, including when a layer (extends) or a plugin'sconfiguresets them.- Farm.js
pluginsrun only theirconfigurehook, infarm devandfarm build, and theirclienthooks, in the browser, next to the app'ssrc/client.ts. The rest of a plugin, from itsruntimehooks to its routes, is ignored, and so arestorage,schema,cron,workflows,docs,theme, andobservability, with a warning. The production server still loads the plugins that have server hooks, asfarm devdoes, so what such a plugin does when it's created runs there:bot()keeps its settings forverifyBot(), for example. The build takes those entries, and only the bindings they use, from thepluginsarray infarm.config.ts, so declare it directly indefineConfig({ plugins: [...] }).
Islands mode renders on Farm.js's own pipeline, so it runs all of these.
Before this flag ran the RSC pipeline it only switched off isolated hydration, so some apps set it
without using React Server Components. If such an app uses auth, integrations or another
feature above that RSC cannot run yet, nothing is installed and it keeps running without React
Server Components, with a warning that says why. { mode: "rsc" } is always treated as a
deliberate choice. farm doctor reports which way an app goes.
A vite.config.ts built with defineConfig from
@farm.js/plugin/rsc and the vite CLI keeps working, as in the
rsc-demo example.
Both setups follow the same route contract:
- Static pages. A page that opts in to static rendering, as in Static rendering,
is prerendered at build time together with its RSC payload. A dynamic route lists its paths with
generateStaticParams(). Client navigation fetches the payload at<page>.rsc(/index.rscfor/), so a prerendered page navigates without reaching the server. A page that any middleware may handle stays server-rendered, because middleware never sees a static file. With i18n a static page prerenders at each URL that names its locale (/fr/about, below the base path); a URL without a locale (the default locale's under"prefix-except-default") redirects visitors whose cookie orAccept-Languagepicks another locale, so it stays server-rendered unlessdetectionis off, androuting: "none"prerenders nothing. A page that asks to be static and fails to render fails the build. - Revalidation. Pages with
revalidaterender on each request and get the sameCache-Controlas in other Farm.js apps (see ISR-style revalidation), on the HTML, on the Flight payload, and on<page>.rscalike, so a CDN serves the page and its client navigations; the pipeline keeps no revalidating cache of its own. So does a static page that renders on request instead of prerendering. Unlike other Farm.js apps, which keep a render that suspends private, the page streams with its policy set before it does, so Suspense content and an error boundary that catches inside it are part of the shared response. A request read ingenerateMetadataor in anasyncpage or layout makes the page private, as in other Farm.js apps, but a read in a component that renders while the page streams is not seen. A shared request has no cookie orAuthorizationheader to read (either makes it private), but its other headers, such asAccept-Languageor the client address, are one visitor's, so do not render them in a page that revalidates. - Metadata. Layouts and pages resolve
metadata,generateMetadata(), and viewport exports in the same order and with the same title templates as other Farm.js apps, and the server renders the same head tags. A client navigation sets the next page's title and replaces the tags Farm.js rendered from metadata (description, canonical and alternate links, robots, Open Graph, JSON-LD) with that page's, as other Farm.js apps do; tags your components render (React 19<meta>and<title>) stay React's. Metadata route files (sitemap.ts,robots.ts,manifest.ts,llms.ts,llms-full.ts) andopengraph-imageandtwitter-imagefiles are served as in other Farm.js apps, and the head names the nearest manifest and images unless the metadata sets them. - Images.
<Image>follows the app'simagesconfig. Withoutsharp,provider: "auto"keeps original image URLs, and the optimizer atimages.pathruns only when it can. - Root layouts. A root layout that renders
<html>owns the document, as in Next.js, and the browser hydrates the whole document. - Base path. Under a
basePath, pages answer below it as in other Farm.js apps: withbasePath: "/console",app/about/page.tsxserves/console/aboutand its payload/console/about.rsc,<Link href="/about">renders/console/about, and a static page prerenders at its URL below the base path. As in other Farm.js apps, the page also answers at/about, andredirect()sends its target as written (with i18n, in the request's locale below the base path). With i18n the locale prefix is stripped too, so/console/fr/aboutmatchesapp/about/page.tsx, which reads its locale withgetLocale()(see Internationalization below). Pages nested in folders that spell out the prefix, as RSC apps had to write them before (app/console/about/page.tsx, orapp/[lang]/about/page.tsxandapp/console/[lang]/about/page.tsxwith i18n), keep their URLs and win over a page at the stripped path: with bothapp/page.tsxandapp/console/page.tsx,/consolerenders the latter. A dynamic or catch-all folder at the root never takes the base path itself, soapp/[[...slug]]/page.tsxsees/console/guidesasguides. When no page matches the stripped path, the path as received is matched. - Internationalization. With
i18n, each request resolves its locale as in other Farm.js apps:getLocale(),t()andformatfrom@farm.js/core/i18n/serverwork in pages, layouts, server actions, route handlers and middleware, and a page URL without a locale redirects to the one the visitor's cookie orAccept-Languagepicks, varying on those headers. Client components read the locale the page rendered with:useLocale(),useTranslations(), and<Link href="/about">, which renders/console/fr/abouton a French page. A link to another locale loads a new document.redirect("/about")from a French page, server action or form sends/console/fr/about, as other Farm.js apps localize it. Farm.js setslanganddiron the document's<html>, also on the one a root layout returns, in place of the layout's own, as other Farm.js apps do; a root layout that is a client component or returns<html>inside another component sets them itself, for example<html lang={getLocale()}>. WithtrailingSlash: true, a locale redirect goes straight to the page's trailing-slash URL. The head carrieshreflangalternate links for each locale andx-default, absolute on the route'smetadataBaseor the request's origin (forwarded headers only withserver.trustProxy), as in other Farm.js apps; a prerendered page has no request, so withoutmetadataBaseits alternates name paths.llms.txtandsitemap.xmllist each page once, at its unprefixed URL, as in other Farm.js apps. - Trailing slashes. Pages follow
trailingSlashas in other Farm.js apps: by default/about/redirects (308) to/about, and withtrailingSlash: true/aboutredirects to/about/,<Link href="/about">renders/about/, and its payload is/about/index.rsc. A payload request at the other spelling redirects to the canonical page's payload, a static page prerenders at its canonical URL, andsitemap.xmlandllms.txtlist each page at that URL. - Redirects, rewrites and headers. The config
redirects(),rewrites()andheaders()apply infarm devand in production as in other Farm.js apps: redirects answer before any route or middleware, a rewrite applies only where no page, API route, route file (sitemap.ts,robots.ts,manifest.ts,llms.ts,llms-full.ts), metadata image or generated agent file (llms.txt,sitemap.xml,robots.txt) answers, and headers apply to whatever answers, API routes, agent files and redirects included; a response middleware let through keepsCache-Control: private, no-store. A payload request matches as its page, so a client navigation follows a redirect to the destination's payload. A static page any of them matches renders on each request instead of prerendering.
A client that loaded an older deployment and fetches a prerendered payload from a newer one does not get the deployment-mismatch reload that a server-rendered payload triggers.
Automatic optimized boundaries
Automatic optimized boundaries are a React-only experiment and are not applied to Preact, Solid, Vue, or Svelte routes.
Farm.js can experimentally render large, non-interactive Server Component regions through the native
Strata renderer. Enable the flag once in farm.config.ts:
import { defineConfig } from "@farm.js/core";
export default defineConfig({
serverComponents: { mode: "rsc" },
experimental: {
optimizedBoundary: true,
},
});Application components remain ordinary JSX:
export default function ArticlePage() {
return (
<article className="prose">
<h1>Representation-aware rendering</h1>
<p>Farm.js selects this host-only region automatically.</p>
</article>
);
}Farm.js evaluates eligible host-element trees on the server and uses Strata only when the region is large enough to benefit. Trees containing Client Components, event handlers, refs, unsupported elements or attributes, unsafe URLs, or other uncertain values retain normal React rendering. The flag does not require an application boundary component or a direct Strata dependency.
The current Strata runtime uses a native Node binding. Keep this experiment on Node deployments until a Wasm or JavaScript fallback is available for edge and Cloudflare worker targets.
Choosing a mode
| Need | Use |
|---|---|
| User-specific data on every request | dynamic = "force-dynamic" |
| Stable docs, marketing, or policy page | dynamic = "force-static" |
| Stable page with scheduled refresh | revalidate = 60 |
| Static shell plus dynamic holes | experimental_ppr = true with Suspense |