nextjs-ppr-patterns
Next.js 16 App Router pages mixing static and dynamic content — Partial Prerendering (PPR) under the Cache Components model. Covers enabling it with cacheComponents (the removed experimental.ppr / experimental_ppr flags), the dynamic-by-default rendering inversion, the Suspense static-shell/dynamic-hole boundary, the 'use cache' directive (automatic keys, cacheLife/cacheTag, children/action pass-through, runtime values as props, serverless durability), async runtime APIs and connection() for non-determinism, page composition from a single hole to parallel dashboards to streaming a Promise into a Client Component with use(), and forms/wizards with updateTag read-your-writes and Activity state preservation. Triggers on PPR, cacheComponents, 'use cache', Suspense streaming, partial prerendering, or static-shell work even when not named explicitly.
- License 许可
- MIT
- 最近更新
- 2026-08-02
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- nextjs-ppr-patterns
- description
- Next.js 16 App Router pages mixing static and dynamic content — Partial Prerendering (PPR) under the Cache Components model. Covers enabling it with cacheComponents (the removed experimental.ppr / experimental_ppr flags), the dynamic-by-default rendering inversion, the Suspense static-shell/dynamic-hole boundary, the 'use cache' directive (automatic keys, cacheLife/cacheTag, children/action pass-through, runtime values as props, serverless durability), async runtime APIs and connection() for non-determinism, page composition from a single hole to parallel dashboards to streaming a Promise into a Client Component with use(), and forms/wizards with updateTag read-your-writes and Activity state preservation. Triggers on PPR, cacheComponents, 'use cache', Suspense streaming, partial prerendering, or static-shell work even when not named explicitly.
02 资源文件 25
- 参考文档AGENTS.md6.7 KB
- 资产文件assets/templates/_template.md1.0 KB
- 参考文档references/_debug-boundaries.md10.0 KB
- 参考文档references/_sections.md3.4 KB
- 参考文档references/cache-in-memory-not-durable-serverless.md1.2 KB
- 参考文档references/cache-keys-are-automatic.md1.2 KB
- 参考文档references/cache-pass-runtime-values-as-props.md2.1 KB
- 参考文档references/cache-pass-through-children-and-actions.md1.3 KB
- 参考文档references/cache-set-lifetime-and-tags.md1.1 KB
- 参考文档references/cache-use-cache-directive.md1.1 KB
- 参考文档references/compose-do-not-opt-out-the-shell.md1.6 KB
- 参考文档references/compose-parallel-holes.md1.6 KB
- 参考文档references/compose-single-dynamic-hole.md1.2 KB
- 参考文档references/compose-stream-to-client-with-use.md1.7 KB
- 参考文档references/mutate-updatetag-vs-revalidatetag.md1.6 KB
- 参考文档references/mutate-wizard-url-driven-steps.md1.7 KB
- 参考文档references/runtime-gate-nondeterminism-with-connection.md1.2 KB
- 参考文档references/runtime-keep-param-routes-static.md1.2 KB
- 参考文档references/runtime-request-apis-force-a-boundary.md1.3 KB
- 参考文档references/setup-dynamic-by-default.md1.3 KB
- 参考文档references/setup-enable-cache-components.md1.2 KB
- 参考文档references/shell-place-boundaries-low.md1.3 KB
- 参考文档references/shell-suspense-does-not-force-dynamic.md1.4 KB
- 参考文档references/shell-suspense-is-the-boundary.md1.2 KB
- 参考文档references/shell-wrap-uncached-data.md1.4 KB
03 SKILL.md 正文
Next.js 16 Partial Prerendering Patterns
Partial Prerendering (PPR) for the Next.js 16 App Router under the Cache Components model — the decisions PPR forces and how to settle them, written so an agent applies them while writing or reviewing code. Contains 21 rules across 6 categories, ordered from easy to complex: enable PPR → understand the static/dynamic boundary → cache → handle runtime data → compose whole pages → build forms and wizards. Each rule corrects a specific wrong default of a model defaulting to Next.js 14/15; there is no rule for things the model already gets right.
Version-specific. This skill targets Next.js 16 (PPR via
cacheComponents, React 19.2). The Next.js 14/15experimental.pprflag andexport const experimental_pprroute export were removed — seesetup-enable-cache-components. For migrating an existing app, see the migration guide.
Write, then verify. These rules are for authoring PPR; they can't tell you what actually rendered. To empirically deconstruct the boundary — diff the static shell against the hydrated DOM to find the dynamic holes, locate the
'use client'islands, measure loading, and explain why a route is dynamic — drivenext buildand a real browser per _debug-boundaries.md.
When to Apply
- Building or reviewing a Next.js 16 page that mixes static chrome with personalized, real-time, or per-request content
- Enabling or migrating PPR (
cacheComponents), or seeing deadexperimental.ppr/experimental_pprcode - Deciding where
<Suspense>boundaries go, or debugging anUncached data was accessed outside of <Suspense>build error - Adding
'use cache',cacheLife,cacheTag, or choosingupdateTag/revalidateTag/refreshafter a mutation - Composing forms, multi-step wizards, dashboards, or streaming server data into interactive Client Components
- Empirically verifying or debugging what actually rendered — which parts are in the static shell vs streamed, where the CSR/SSR boundary is, and why a route went dynamic
Rule Categories
| # | Category | Prefix | Covers |
|---|---|---|---|
| 1 | Setup & Mental Model | setup- |
Enabling PPR with cacheComponents; the removed experimental flags; dynamic-by-default / opt-in caching inversion |
| 2 | The Suspense Boundary | shell- |
<Suspense> as the static/dynamic seam; the build error; boundary granularity; what Suspense does not do |
| 3 | Caching with 'use cache' |
cache- |
Directive levels; automatic keys; runtime values as props; pass-through; cacheLife/cacheTag; serverless durability |
| 4 | Runtime APIs & Non-Determinism | runtime- |
Async request APIs forcing a boundary; generateStaticParams; connection() for randomness/time |
| 5 | Page Composition Recipes | compose- |
Single hole → parallel dashboard → Promise + use() streaming → not opting the whole app out of the shell |
| 6 | Forms, Mutations & Wizards | mutate- |
updateTag vs revalidateTag vs refresh; URL-driven wizard steps; <Activity> field preservation |
Quick Reference
1. Setup & Mental Model
setup-enable-cache-components— Enable PPR viacacheComponents: true; theexperimental.ppr/experimental_pprflags are removedsetup-dynamic-by-default— Everything renders at request time; caching is opt-in via'use cache'(andfetchis no longer cached)
2. The Suspense Boundary
shell-suspense-is-the-boundary—<Suspense>is the static-shell/dynamic-stream seam, not a spinnershell-wrap-uncached-data— Uncached/runtime reads must be wrapped (or'use cache'd) or the build errorsshell-suspense-does-not-force-dynamic— Suspense alone does not make synchronous work dynamicshell-place-boundaries-low— Wrap the dynamic leaf, not the whole page, so the shell stays large
3. Caching with 'use cache'
cache-use-cache-directive— Mark static/cacheable work at the function / component / page / layout / file levelcache-keys-are-automatic— Arguments and closures form the cache key; pass varying inputs as argscache-pass-runtime-values-as-props— You can't readcookies()/headers()inside a cached scope; pass values incache-pass-through-children-and-actions— Pass dynamicchildrenand Server Actions through a cached component untouchedcache-set-lifetime-and-tags—cacheLifecontrols TTL,cacheTagenables on-demand invalidationcache-in-memory-not-durable-serverless— In-memory cache isn't durable on serverless; use'use cache: remote'
4. Runtime APIs & Non-Determinism
runtime-request-apis-force-a-boundary— Asynccookies/headers/searchParams/paramsforce a dynamic boundaryruntime-keep-param-routes-static—generateStaticParamskeeps[slug]routes in the static shellruntime-gate-nondeterminism-with-connection— GateMath.random/Date.now/cryptobehindconnection(), or cache the value
5. Page Composition Recipes
compose-single-dynamic-hole— The baseline: static shell + one<Suspense>holecompose-parallel-holes— One boundary per widget → parallel streaming, no waterfallcompose-stream-to-client-with-use— Pass an un-awaited Promise and unwrap withuse()in a Client Componentcompose-do-not-opt-out-the-shell— Don't defer the whole app to silence a boundary error
6. Forms, Mutations & Wizards
mutate-updatetag-vs-revalidatetag—updateTag(read-your-writes) vsrevalidateTag(tag, profile)(SWR) vsrefresh()mutate-wizard-url-driven-steps— URL-driven steps + static chrome +<Activity>field preservation
How to Use
Read a reference file when its decision comes up. Each rule names the wrong default it corrects, then shows the canonical way (with an incorrect/correct contrast only where the wrong way is a real trap). If you're starting cold, read setup- first — the rest assumes the dynamic-by-default mental model.
- Section definitions — category structure and ordering
- Boundary debugging — empirically deconstruct the static/dynamic boundary and loading with
next buildand chrome-devtools-mcp (via mcporter); use it when a PPR result surprises you or you're chasing ablocking-routeerror - Rule template — for adding new rules
- AGENTS.md — auto-built table of contents across all rules
Related Skills
nextjs— broader Next.js 16 App Router best practices (caching, server components, routing, hygiene)opinionated-nextjs-patterns— full opinionated architecture (data layer, mutations, client boundaries) that uses these PPR patternsreact-fetch-cache-patterns— request orchestration and client-side caching for data-heavy React UIs
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| references/_debug-boundaries.md | Empirical CSR/SSR boundary & loading debugging (next build + chrome-devtools-mcp via mcporter) |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and source references |
04 同仓库更多 Skills
zustand
Rules and standards for state management using Zustand in React and Next.js. Use when implementing client-side stores, persistence with localStorage, or preventing SSR hydration mismatch.
zod
Zod v4 schema validation best practices. Use when defining schemas, utilizing safeParse, or customizing error messages.
upstash-ratelimit
Rules, standards, and references for rate limiting in serverless environments using Upstash Ratelimit. Use when implementing rate limiting, configuring Upstash Redis, or handling request blocking.
ui-design
UI/UX and frontend design best practices guidelines (formerly frontend-design). This skill should be used when writing, reviewing, or designing frontend code to ensure accessibility, performance, and usability. Triggers on tasks involving HTML structure, CSS styling, responsive layouts, form design, animations, or accessibility improvements.
typescript
TypeScript performance, tsconfig, type errors, async patterns — triggered when the user asks to "optimize TypeScript performance", "speed up tsc compilation", "configure tsconfig.json", "fix type errors", "improve async patterns", or encounters TS errors (TS2322, TS2339, "is not assignable to"). Also triggers on .ts, .tsx, .d.ts file work involving type definitions, module organization, or memory management. Does NOT cover TypeScript basics, framework-specific patterns, or testing.
typescript-refactor
TypeScript and TSX refactoring and modernization guidelines from a principal specialist perspective, current to TypeScript 6.0 and React 19. This skill should be used when refactoring, reviewing, or modernizing TypeScript or React/TSX code for type safety, compiler performance, and idiomatic patterns. Triggers on tasks involving type architecture, narrowing, generics, discriminated unions, error handling, React component and hook typing, or migration to modern TypeScript features (satisfies, using, const type parameters, inferred type predicates, isolatedDeclarations, erasable syntax, import attributes).