Next.js flags
install
source · Clone the upstream repo
git clone https://github.com/vercel/next.js
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/vercel/next.js "$T" && mkdir -p ~/.claude/skills && cp -r "$T/.agents/skills/flags" ~/.claude/skills/vercel-next-js-flags && rm -rf "$T"
manifest:
.agents/skills/flags/SKILL.mdsource content
Feature Flags
Use this skill when adding or changing framework feature flags in Next.js internals.
Required Wiring
All flags need:
config-shared.ts (type) → config-schema.ts (zod). If the flag is consumed in user-bundled code (client components, edge routes, app-page.ts template), also add it to define-env.ts for build-time injection. Runtime-only flags consumed exclusively in pre-compiled bundles can skip define-env.ts.
Where the Flag Is Consumed
Client/bundled code only (e.g.
__NEXT_PPR in client components): define-env.ts is sufficient. Webpack/Turbopack replaces process.env.X at the user's build time.
Pre-compiled runtime bundles (e.g. code in
app-render.tsx): The flag must also be set as a real process.env var at runtime, because app-render.tsx runs from pre-compiled bundles where define-env.ts doesn't reach. Two approaches:
- Runtime env var: Set in
+next-server.ts
. Both code paths stay in one bundle. Simple but increases bundle size.export/worker.ts - Separate bundle variant: Add DefinePlugin entry in
(scoped tonext-runtime.webpack-config.js
), new taskfile tasks, updatebundleType === 'app'
selector, and still set env var inmodule.compiled.js
+next-server.ts
for bundle selection. Eliminates dead code but adds build complexity.export/worker.ts
For runtime flags, also add the field to the
NextConfigRuntime Pick type in config-shared.ts.
Runtime-Bundle Model
- Runtime bundles are built by
(rspack) vianext-runtime.webpack-config.js
bundle tasks.taskfile.js - Bundle selection occurs at runtime in
based onsrc/server/route-modules/app-page/module.compiled.js
vars.process.env - Variants:
= up to 16 bundles per route type.{turbo/webpack} × {experimental/stable/nodestreams/experimental-nodestreams} × {dev/prod}
affects user bundling, not pre-compiled runtime internals.define-env.ts
checks inprocess.env.X
are either replaced by DefinePlugin at runtime-bundle-build time, or read as actual env vars at server startup. They are NOT affected by the user's defines fromapp-render.tsx
.define-env.ts- Gotcha: DefinePlugin entries in
must be scoped to the correctnext-runtime.webpack-config.js
(e.g.bundleType
only, notapp
) to avoid replacing assignment targets inserver
.next-server.ts
Related Skills
- DCE-safe require patterns and edge constraints$dce-edge
- entry-base boundaries and vendored React$react-vendoring
- reproduction and verification workflow$runtime-debug