nextjs-internals
Use when the user asks why a Next.js route is dynamic, how the App Router renders and streams, the RSC payload, partial prerendering, Cache Components / 'use…
от j4flmao★ 47 звёзд на GitHub
Установить nextjs-internals в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Next.js Internals: Rendering, Streaming and Caching
Purpose
Explain the App Router request lifecycle precisely enough to debug it: how a route is classified static or dynamic, what the RSC payload is, how streaming and Partial Prerendering (PPR) work, and which cache layer holds which data. Facts target Next.js 16 (Cache Components, proxy.ts, Turbopack default) with notes where Next.js 15 differs.
Agent Protocol
Trigger
"RSC payload", "why is this route dynamic", "partial prerendering", "cacheComponents", "use cache", "cacheLife", "cacheTag", "router cache", "stale data after mutation", "streaming SSR".
Input Context
- Next.js major version and whether
cacheComponentsis enabled innext.config.ts. next buildroute output and the route's code (data access,cookies(),headers(),searchParams).- Deployment target (Node server, Vercel, static export, self-hosted with multiple instances).
Output Artifact
Diagnosis of the route's rendering mode plus the minimal code/config change.
Response Format
Route: {path} Mode: {static|dynamic|partially prerendered}
Cause: {API or fetch that made it dynamic}
Cache layers involved: {use cache|fetch cache|router cache|CDN}
Fix: {code change}
Invalidation: {revalidateTag|updateTag|revalidatePath|refresh}
Request Lifecycle
proxy.ts(formerlymiddleware.ts, renamed in Next.js 16) runs first: rewrites, redirects, header/cookie checks. Keep it light; it is not for full auth logic or data fetching.- Router matches the segment tree (
layout→template→page, plusloading,error,not-found). - Server Components render to the RSC payload: a streamed serialization of the server tree with placeholders and module references for Client Components and their serialized props.
- On a full page load the payload + Client Components are SSR'd to HTML; the payload is also inlined so React can hydrate without refetching.
- On client navigation only the RSC payload for changed segments is fetched; shared layouts are preserved and not re-rendered.
Static vs Dynamic
A route is prerendered at build time unless something request-specific is used during render:
- Request APIs:
cookies(),headers(),draftMode(), readingsearchParams,connection(). - Uncached data access (in Next.js 15+,
fetchis not cached by default). export const dynamic = 'force-dynamic'(route segment config; not compatible with Cache Components mode).
In Next.js 15+, params, searchParams, cookies() and headers() are async and must be awaited.
Cache Components (Next.js 16, opt-in)
// next.config.ts
import type { NextConfig } from 'next';
const nextConfig: NextConfig = { cacheComponents: true };
export default nextConfig;
With it enabled, everything is dynamic by default and you opt into caching with the 'use cache' directive. The static shell is prerendered, and dynamic parts must sit inside <Suspense> so they stream in (this is Partial Prerendering, now the default model; the old experimental.ppr flag is removed).
// app/products/[id]/page.tsx
import { Suspense } from 'react';
import { cacheLife, cacheTag } from 'next/cache';
import { cookies } from 'next/headers';
async function getProduct(id: string) {
'use cache';
cacheLife('hours');
cacheTag(`product:${id}`);
return db.product.findUniqueOrThrow({ where: { id } });
}
export default async function Page({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const product = await getProduct(id);
return (
<main>
<h1>{product.name}</h1>
<Suspense fallback={<p>Loading your price…</p>}>
<PersonalPrice productId={id} />
</Suspense>
</main>
);
}
async function PersonalPrice({ productId }: { productId: string }) {
const tier = (await cookies()).get('tier')?.value ?? 'standard';
return <p>{await priceFor(productId, tier)}</p>;
}
Cached functions cannot read cookies()/headers() directly; read them outside and pass values as arguments (arguments become part of the cache key).
Invalidation (Server Functions / Route Handlers)
| API | Semantics | Use for |
|---|---|---|
updateTag(tag) |
Expire and read fresh data in the same request (read-your-writes); Server Functions only | User just edited their own data |
revalidateTag(tag, profile) |
Stale-while-revalidate; Next.js 16 expects a cacheLife profile as 2nd arg (e.g. 'max') |
Background content updates, webhooks |
revalidatePath(path) |
Invalidate everything rendered for a path | Coarse invalidation |
refresh() |
Refresh uncached data on the client router from a Server Function | Counters, notifications |
router.refresh() |
Client-side refetch of current route payload | After non-Next mutations |
Cache Layers
| Layer | Where | Holds | Cleared by |
|---|---|---|---|
'use cache' / data cache |
Server (in-memory or custom cache handler) |
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл nextjs-internals?
Use when the user asks why a Next.js route is dynamic, how the App Router renders and streams, the RSC payload, partial prerendering, Cache Components / 'use cache', the router cache or the request lifecycle. Produces a diagnosis of static vs dynamic rendering and stale data in Next.js 15/16. Not for everyday App Router features (use react-nextjs).
Как установить скилл nextjs-internals?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл nextjs-internals запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…