|
| 1 | +# next-runtime-snapshot |
| 2 | + |
| 3 | +End-to-end devframe demo with a **Next.js App Router** SPA. Shows that any |
| 4 | +React+Next.js build is a drop-in replacement for a Preact+Vite SPA: devframe |
| 5 | +serves the static export, the client calls into the host Node process via |
| 6 | +type-safe RPC. |
| 7 | + |
| 8 | +## What it shows |
| 9 | + |
| 10 | +- `next-runtime-snapshot:system` — a `static` RPC function. Runs once at |
| 11 | + build time when baked into a static dump, otherwise resolved live over |
| 12 | + WebSocket. Returns Node version, platform/arch, pid, cwd, start time. |
| 13 | +- `next-runtime-snapshot:memory` — a `query` RPC function. Re-runnable; |
| 14 | + the UI has a refresh button that re-invokes the handler. |
| 15 | +- `next-runtime-snapshot:env` — a `query` RPC function with valibot-validated |
| 16 | + args (`pattern`, `limit`). Lists environment variables matching a regex, |
| 17 | + redacting keys that look secret. |
| 18 | +- Next.js App Router with `'use client'` components calling |
| 19 | + `connectDevframe()` once and passing the RPC client through React context. |
| 20 | + |
| 21 | +## Run it |
| 22 | + |
| 23 | +```sh |
| 24 | +pnpm -C examples/next-runtime-snapshot run build # next build → static export → dist/client/ |
| 25 | +pnpm -C examples/next-runtime-snapshot run dev # node bin.mjs → devframe CLI |
| 26 | +``` |
| 27 | + |
| 28 | +Open `http://localhost:9899/__next-runtime-snapshot/` — the three cards |
| 29 | +populate from RPC, the env filter is debounced, and the footer shows the |
| 30 | +connection backend. |
| 31 | + |
| 32 | +## Build a static deployment |
| 33 | + |
| 34 | +```sh |
| 35 | +pnpm -C examples/next-runtime-snapshot run cli:build |
| 36 | +``` |
| 37 | + |
| 38 | +Output lands in `dist/static/`. Serve it from any static host (`npx serve |
| 39 | +dist/static`) — the `static` and `query` RPCs that opted into the dump still |
| 40 | +work because the snapshot is baked at build time. |
| 41 | + |
| 42 | +## Next.js config — three settings worth knowing |
| 43 | + |
| 44 | +`src/client/next.config.mjs` is short on purpose. The three non-defaults |
| 45 | +each correspond to a devframe design principle: |
| 46 | + |
| 47 | +- **`output: 'export'`** — devframe owns the HTTP server; Next.js produces a |
| 48 | + fully static SPA. No Next.js runtime is required at serve time, so server |
| 49 | + components and route handlers are rendered at build time only. |
| 50 | +- **`assetPrefix: '.'`** — relative asset paths so the same build works at |
| 51 | + `/`, `/__next-runtime-snapshot/`, and any custom base. Devframe's design |
| 52 | + principle: SPAs own their base path at runtime, discovered from |
| 53 | + `document.baseURI`. |
| 54 | +- **`trailingSlash: true`** — emits `foo/index.html` rather than `foo.html`, |
| 55 | + which composes cleanly with devframe's static handler directory-with-index |
| 56 | + resolution. |
| 57 | + |
| 58 | +The `dist/client/` artifact is a copy of `src/client/out/` (Next.js's |
| 59 | +default export directory) — the `build` script just renames it so the |
| 60 | +example matches the layout used by the other examples in this repo. |
0 commit comments