Skip to content

feat(examples): add next-runtime-snapshot Next.js example + docs#22

Merged
antfu merged 2 commits into
mainfrom
antfu/docs-nextjs-guide
May 22, 2026
Merged

feat(examples): add next-runtime-snapshot Next.js example + docs#22
antfu merged 2 commits into
mainfrom
antfu/docs-nextjs-guide

Conversation

@antfu
Copy link
Copy Markdown
Contributor

@antfu antfu commented May 22, 2026

Summary

  • New examples/next-runtime-snapshot proves Next.js App Router works as a devframe SPA via static export (output: 'export', assetPrefix: '.', trailingSlash: true); three RPC functions surface host Node runtime info — system (static), memory (query), and env (query with valibot-validated args + secret redaction).
  • Adds a "Next.js SPA setup" recipe to docs/guide/standalone-cli.md alongside the existing Nuxt one, lists the example in built-with.md, and broadens the pnpm frontend catalog to React + Next.
  • Ships 8 vitest specs (in-process server boot, all three RPCs, connection-meta discovery) and 6 Playwright specs (dev + static modes); wires the example into turbo.json, vitest.config.ts, and playwright.config.ts, with eslint ignores extended for .next / out / next-env.d.ts.

Test plan

  • pnpm test — 31 files / 328 tests passing, including the new vitest suite
  • pnpm lint && pnpm typecheck — clean
  • pnpm -C docs run docs:build — VitePress builds cleanly with the new recipe
  • pnpm -C examples/next-runtime-snapshot run build — Next.js static export → dist/client/
  • node examples/next-runtime-snapshot/bin.mjs — dev server on http://localhost:9899/__next-runtime-snapshot/
  • node examples/next-runtime-snapshot/bin.mjs build --out-dir dist/static — static dump emits __connection.json + baked system snapshot
  • pnpm test:e2e — Playwright e2e suite (verified locally against manually-booted servers)

Adds examples/next-runtime-snapshot proving Next.js App Router works as a
devframe SPA via static export — three RPC functions (system / memory / env)
surface host Node runtime info, exercising static + query types and
valibot-validated args. Documents the Next.js SPA setup recipe alongside
the existing Nuxt one, broadens the pnpm frontend catalog to React + Next,
and ships vitest + Playwright coverage.
Copilot AI review requested due to automatic review settings May 22, 2026 02:12
@netlify
Copy link
Copy Markdown

netlify Bot commented May 22, 2026

Deploy Preview for devfra ready!

Name Link
🔨 Latest commit 071416f
🔍 Latest deploy log https://app.netlify.com/projects/devfra/deploys/6a0fbf3f6216b6000807f2b7
😎 Deploy Preview https://deploy-preview-22--devfra.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new end-to-end Next.js App Router example (examples/next-runtime-snapshot) to demonstrate using a Next.js static export as a devframe SPA, plus accompanying docs, tooling wiring, and test coverage (Vitest + Playwright) integrated into the monorepo.

Changes:

  • Introduces examples/next-runtime-snapshot (Next.js static export SPA) with three RPC functions (system, memory, env) and CLI wiring.
  • Expands the monorepo test/build setup to include the new example (turbo tasks, vitest workspace, Playwright webServers + e2e specs).
  • Updates docs to add a “Next.js SPA setup” recipe and lists the new example in “built-with”.

Reviewed changes

Copilot reviewed 26 out of 27 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
vitest.config.ts Adds the new example to the Vitest workspace list.
turbo.json Adds turbo build and cli:build tasks for the new example.
tests/e2e/next-runtime-snapshot-static.spec.ts Adds Playwright coverage for the static-export mode.
tests/e2e/next-runtime-snapshot-dev.spec.ts Adds Playwright coverage for dev (websocket) mode.
pnpm-workspace.yaml Extends catalogs for Next/React and adjusts build-allowlist.
pnpm-lock.yaml Locks newly introduced dependencies (Next/React ecosystem + transitive deps).
playwright.config.ts Registers dev + static webServers for the new example.
examples/next-runtime-snapshot/tsconfig.json Adds TS configuration for the example package.
examples/next-runtime-snapshot/tests/next-runtime-snapshot.test.ts Adds Vitest coverage for RPC behavior and connection meta.
examples/next-runtime-snapshot/tests/_utils.ts Adds an in-process server bootstrap helper for tests.
examples/next-runtime-snapshot/src/devframe.ts Defines the devframe + RPC functions (system/memory/env) and SPA config.
examples/next-runtime-snapshot/src/client/tsconfig.json Adds TS config for the Next.js client project.
examples/next-runtime-snapshot/src/client/next.config.mjs Configures Next.js for static export compatible with devframe mounting.
examples/next-runtime-snapshot/src/client/app/page.tsx Implements the main page UI and status bar.
examples/next-runtime-snapshot/src/client/app/layout.tsx Adds app layout + metadata for the Next.js app.
examples/next-runtime-snapshot/src/client/app/globals.css Adds example styling for the UI.
examples/next-runtime-snapshot/src/client/app/components/snapshot-system.tsx UI card for the system RPC.
examples/next-runtime-snapshot/src/client/app/components/snapshot-memory.tsx UI card for the memory RPC + refresh.
examples/next-runtime-snapshot/src/client/app/components/snapshot-env.tsx UI card for the env RPC + debounced regex filter.
examples/next-runtime-snapshot/src/client/app/components/connect.tsx Connects to devframe once and exposes RPC via React context.
examples/next-runtime-snapshot/README.md Documents what the example demonstrates and how to run/build it.
examples/next-runtime-snapshot/package.json Adds scripts/deps for building and running the example.
examples/next-runtime-snapshot/bin.mjs Adds the CLI entrypoint for dev/build modes.
examples/next-runtime-snapshot/.gitignore Ignores Next build outputs and dist artifacts.
eslint.config.js Ignores Next build artifacts (.next, out, next-env.d.ts).
docs/guide/standalone-cli.md Adds a Next.js SPA setup recipe alongside the existing Nuxt guidance.
docs/guide/built-with.md Lists the new Next.js example among end-to-end demos.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +121 to +131
if (pattern) {
try {
regex = new RegExp(pattern, 'i')
}
catch {
regex = null
}
}
const keys = Object.keys(process.env).sort()
const matched = regex ? keys.filter(k => regex.test(k)) : keys
const entries = matched.slice(0, limit).map(k => redact(k, process.env[k] ?? ''))
Comment on lines +50 to +57
// SPA mount is conditional — RPC-only tests don't need the built dist.
// Tests that fetch HTML should run `pnpm run build` first.
try {
mountStaticHandler(app, basePath, resolve(distDir))
}
catch {
// No dist yet; that's fine for RPC-only tests.
}
Comment on lines +33 to +44
<dl className="kv">
<span className="k">node</span>
<span className="v">{info.node}</span>
<span className="k">platform</span>
<span className="v">{`${info.platform} (${info.arch})`}</span>
<span className="k">pid</span>
<span className="v">{info.pid}</span>
<span className="k">cwd</span>
<span className="v">{info.cwd}</span>
<span className="k">started</span>
<span className="v">{formatStartedAt(info.startedAt)}</span>
</dl>
Comment on lines +58 to +71
<dl className="kv">
<span className="k">uptime</span>
<span className="v">{fmtUptime(snap.uptimeSeconds)}</span>
<span className="k">rss</span>
<span className="v">{fmtBytes(snap.memory.rss)}</span>
<span className="k">heap used</span>
<span className="v">{fmtBytes(snap.memory.heapUsed)}</span>
<span className="k">heap total</span>
<span className="v">{fmtBytes(snap.memory.heapTotal)}</span>
<span className="k">external</span>
<span className="v">{fmtBytes(snap.memory.external)}</span>
<span className="k">array buffers</span>
<span className="v">{fmtBytes(snap.memory.arrayBuffers)}</span>
</dl>
Comment on lines +46 to +51
<input
type="text"
value={pattern}
onChange={e => setPattern(e.target.value)}
placeholder="Regex filter (case-insensitive) — e.g. NODE | PATH | HOME"
/>
Comment on lines +22 to +23
const initialRss = await memCard.locator('.kv .v').nth(1).textContent()
expect(initialRss).toMatch(/\d+(?:\.\d+)?\s*MB/)
Comment thread docs/guide/standalone-cli.md Outdated
```json [package.json]
{
"scripts": {
"build": "next build src/client && rm -rf dist/client && cp -r src/client/out dist/client"
…shot

- Invalid regex pattern in `env` RPC now matches nothing rather than
  silently widening to all keys (could leak vars the redaction
  heuristic doesn't catch). Adds a vitest case to cover.
- Drop dead try/catch around `mountStaticHandler()` in test utils — it
  doesn't throw on missing distDir.
- Replace `<dl>` with `<span>` children with `<div className="kv">` in
  the system + memory cards (invalid definition-list structure).
- Add `aria-label` to the env filter input.
- Coalesce `Locator.textContent()` to `''` in the Playwright dev spec.
- Match the example's actual build script in the docs snippet
  (`mkdir -p dist` before `cp -r`).
@antfu antfu merged commit 890b20d into main May 22, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants