This is a basic example demonstrating the core features of Farm.js without any complex dependencies or configurations.
- ✅ File-based routing
- ✅ React Server Components
- ✅ TypeScript support
- ✅ Zero configuration setup
- ✅ Vite-powered development
- ✅ Layouts and nested routing
# From the root of the monorepo
pnpm install
pnpm build
# Start the example
cd examples/basic
pnpm devThe example will be available at http://localhost:3000.
This example enables route-level loading.tsx and error.tsx boundaries with:
// examples/basic/farm.config.ts
export default defineConfig({
serverComponents: true,
});serverComponents: true is the important part for the current loading/error boundary behavior in this example.
The example also keeps deployment and Vite tweaks in the same file:
export default defineConfig({
deploy: {
target: "vercel",
},
vite: {
// optional Vite customization
},
});No root vite.config.ts or vercel.json is required for the basic example.
This example exposes agent-readable markdown mirrors for a few normal pages:
export default defineConfig({
md: {
expose: ["/", "/about", "/contact"],
cache: 60,
},
});With the dev server running, /about.md renders the same /about page as text/markdown.
PPR is experimental and gated by experimental.ppr: true in farm.config.ts (this example
enables it). With the flag on, the /ppr-demo page opts into static-shell caching:
export const experimental_ppr = true;
export const revalidate = 60;The first request returns X-Farm-PPR: miss; the next matching request returns X-Farm-PPR: hit.
Cached hits serve the Suspense fallback shell first, then refresh the dynamic island with a
same-origin bypass request.
Farm can emit runtime events for cache, PPR, rendering, routes, APIs, integrations, middleware,
storage, build, plugins, and errors. This example can enable the default logs or send events to a
custom handler from farm.config.ts:
export default defineConfig({
observability: {
logs: true,
onEvent(event) {
if (event.type.startsWith("ppr.") || event.type.startsWith("cache.")) {
console.log(event);
}
},
},
});If you change code in packages/farm or packages/farmjs-plugin, rebuild the workspace packages before restarting this example:
pnpm --filter @farm.js/core build
pnpm --filter @farm.js/plugin build
cd examples/basic
pnpm devThe example consumes the built package output from dist, so source changes in the framework packages are not picked up until they are rebuilt.
farm.config.ts
src/
app/
layout.tsx # Root layout with navigation
page.tsx # Home page (/)
error.tsx # Route-level error boundary (catches errors for this segment)
loading.tsx # Route-level loading UI (Suspense fallback while segment loads)
about/
page.tsx # About page (/about)
contact/
page.tsx # Contact page (/contact)
error.tsx– Catches runtime errors during SSR or client render for that route segment. Receiveserrorandreset(). When an error is thrown (e.g. in a page or async component), this UI is shown instead; "Try again" callsreset()to re-render.loading.tsx– Shown while the route segment is loading (e.g. async page/layout, streaming). Wraps the segment in a Suspense boundary; you get instant loading states during navigation and SSR streaming.
Important notes:
- You do not manually import
loading.tsxintopage.tsx - The segment must suspend or throw for the boundary to appear
loading.tsxcan stay a normal component; add'use client'only if it truly needs client-only APIs- See
src/app/boundaries/loadingfor the streamed loading example - See
src/app/boundaries/suspensefor a plain React Suspense example
- File-based Routing: Notice how each
page.tsxfile creates a new route - Layouts: The root layout provides consistent navigation across all pages
- TypeScript: Full type safety with
PagePropsand other Farm.js types - Zero Config: No complex configuration needed - just start coding!
After exploring this basic example, check out:
- Local-first Example - A task list with data that syncs and works offline
- Stripe Integration Example - Checkout and billing with
@farm.js/stripe - Documentation - Complete Farm.js documentation