ai newsDi., 1. Dez.

Next.js 16.4 empfiehlt Cache Components als Standard

Next.js 16.4 macht Cache Components zur empfohlenen Voreinstellung; Next.js 17 soll sie vollständig übernehmen. Neu sind unter anderem ensureStatic, navigation() und prefetch(), Verbesserungen an Turbopack sowie React 19.3.

InfoQMontag 07:46 · 30.11.DE3 Min. Lesezeit
Bild: InfoQ

Neue Projekte, die mit create-next-app erstellt werden, kommen nun von Anfang an mit cacheComponents: true und partialPrefetching: true in der next.config.ts. Wie BuildMVPFast es formulierte: "deine next.config.ts enthält zwei Zeilen, die du nie angefragt hast". Bestehende Apps setzen diese Optionen von Hand:

const nextConfig: NextConfig = { cacheComponents: true, partialPrefetching: true, }; Zwei neue APIs sollen Cache Components berechenbar halten. ensureStatic, das aus einem Route- oder Layout-File exportiert wird, lässt den Build fehlschlagen, wenn dynamischer Inhalt in das Shell-Gerüst einer Seite, einen Prefetch oder eine vollständige Navigation gelangt. Abhishek Gupta beschrieb es im CODERCOPS-Blog als "einen günstigen Weg, eine Kostenregression bereits im Code Review zu stoppen statt auf der Rechnung", und empfahl, es im Root-Layout anzuwenden und dort zu lockern, wo Seiten tatsächlich dynamische Daten benötigen.

Die zweite Ergänzung sind die Funktionen navigation() und prefetch() aus next/cache, die zwischengespeicherte Inhalte von einem Prefetch ausschließen und bis zu einer echten Navigation aufschieben. Gupta nannte navigation() "die nützlichste Neuerung dieses Releases" für Inbox-artige Seiten, bei denen das Prefetching jedes sichtbaren Links zuvor komplette Nachrichten-Threads über die Leitung zog:

import { navigation } from 'next/cache'; async function Thread({ id }) { await navigation(); const thread = await getThread(id); //... } Der Festplatten-Cache von Turbopack benötigt dank Zstandard-Komprimierung 20 bis 25 Prozent weniger Speicherplatz, lazy server HMR kompiliert nur die aktuell sichtbare Route neu, und Production-Bundles liefern kürzere CSS-Module-Klassennamen und verschleierte Exporte. Das Release zieht React 19.3 mit stabilen View Transitions, Fragment Refs und der neuen browser()-API herein, während der experimentelle Rust-Port des React Compilers nach Allokationsänderungen durch das Turbopack-Team seinen Speicherverbrauch um 30 Prozent und seine Compile-Zeit um 15 Prozent reduziert bekam.

Das Release setzt verstärkt auf agentengetriebene Workflows. Ein neuer Befehl npx next@canary upgrade --agent=latest liefert versionszugeordnete Migrationsanleitungen, Codemods und Verifikationsschritte an einen Coding-Agenten, während experimental.agentUpgrade Entwickler über next dev darauf hinweist, wenn ein relevantes Security- oder Minor-Release verfügbar ist. Ein Opt-in-Flag experimental.agentFeedback erlaubt Agenten, Entwurfsberichte über Framework-Probleme zur Prüfung vorzubereiten, bevor irgendetwas gesendet wird.

Die Reaktionen wurden durch ein außerplanmäßiges Security-Update am 14. Oktober gedämpft, das zwei Critical- und eine High-Schwachstelle in Upstream-Abhängigkeiten schließt. Auf Reddit bemerkte ein Nutzer Probleme bei der Verwendung von OpenNext:

Anmerkung zum Self Hosting mit OpenNext in dieser Version, es scheint unsere Seitenleistung etwas zu verlangsamen, daher lohnt es sich, es selbst zu testen und nicht einfach davon auszugehen, dass es funktioniert

Nachtrag: Um das zu präzisieren, ich glaube, der next-Server versucht, die App-Shell auf dem Server zu rendern, aber mit OpenNext erhält man kein Edge-Caching und keine Stream-Continuation in der Form, wie Vercel sie bietet

Bestehende Apps können mit der oben genannten Agent-CLI migrieren oder der Upgrade-Anleitung folgen, die die mit 16.0 festgelegten Baselines von Node.js 20.9 und TypeScript 5.1 beibehält. Vercel veröffentlicht zudem dedizierte Skills zur Einführung von Cache Components und Partial Prefetching, die ein Coding-Agent direkt anwenden kann. Konkurrenz-Frameworks wie Remix, Astro und TanStack Start setzen weiterhin auf einfachere mentale Modelle, während Next.js weiter in Richtung explizites Caching und Agent-first-Migrationstooling geht.

Next.js ist ein Open-Source-React-Framework, das von Vercel entwickelt und gepflegt wird. Es erweitert React um dateibasiertes Routing, serverseitiges Rendering und die Server Components des App Router und wird für alles von statischen Websites bis zu großen dynamischen Anwendungen breit eingesetzt.

Präsentiert von: Kiran Gangadharappa - Engineering Advisor bei Harness, und Scott Davis - Senior Engineering Manager bei Harness

Automatisch übersetzt. Das Original auf Englisch ist unten aufklappbar.

Original (Englisch) anzeigen

New projects scaffolded with create-next-app now arrive with cacheComponents: true and partialPrefetching: true in next.config.ts from the start. As BuildMVPFast put it, "your next.config.ts has two lines you didn't ask for". Existing apps set them by hand:

const nextConfig: NextConfig = { cacheComponents: true, partialPrefetching: true, }; Two new APIs aim to keep Cache Components predictable. ensureStatic, exported from a route or a layout, fails the build if dynamic content ever sneaks into a page's shell, prefetch or full navigation. Writing on the CODERCOPS blog, Abhishek Gupta described it as "a cheap way to stop a cost regression in code review rather than on the invoice", and suggested applying it to the root layout then loosening it where pages genuinely need dynamic data.

The second addition is the navigation() and prefetch() functions from next/cache, which exclude cached content from a prefetch and defer it until a real navigation. Gupta called navigation() "the most useful addition in the release" for inbox-style pages, where prefetching every visible link previously pulled entire message threads over the wire:

import { navigation } from 'next/cache'; async function Thread({ id }) { await navigation(); const thread = await getThread(id); //... } Turbopack's disk cache uses 20 to 25 percent less space thanks to Zstandard compression, lazy server HMR only recompiles the route in view, and production bundles ship shorter CSS Module class names and mangled exports. The release pulls in React 19.3 with stable View Transitions, Fragment Refs and the new browser() API, while the experimental Rust port of the React Compiler had its memory use cut by 30 percent and its compile time by 15 percent after allocation changes from the Turbopack team.

The release leans further into agent-driven workflows. A new npx next@canary upgrade --agent=latest command feeds version-matched migration guides, codemods and verification steps to a coding agent, while experimental.agentUpgrade nudges developers from next dev when a relevant security or minor release is out. An opt-in experimental.agentFeedback flag lets agents prepare draft reports on framework issues for review before anything is sent.

Reactions were tempered by an out-of-band security update on October 14, patching two Critical and one High vulnerability in upstream dependencies. On Reddit, one user noticed issues when using OpenNext:

Note about self hosting with OpenNext on this, it seems to slow down our page performance a little bit so worth testing yourself and not just assuming it works

Edit: To expand on this, I think next server is trying to render the app shell on the server but OpenNext you don’t get edge caching and stream continuation in the same way Vercel offer

Existing apps can migrate with the agent CLI above or follow the upgrade guide, which keeps the Node.js 20.9 and TypeScript 5.1 baselines set in 16.0. Vercel also publishes dedicated Skills for adopting Cache Components and Partial Prefetching, which a coding agent can apply directly. Framework rivals such as Remix, Astro and TanStack Start continue to lean on simpler mental models, while Next.js moves further into explicit caching and agent-first migration tooling.

Next.js is an open-source React framework developed and maintained by Vercel. It extends React with file-based routing, server-side rendering, and the App Router's Server Components, and is widely used for everything from static sites to large-scale dynamic applications.

Presented by: Kiran Gangadharappa - Engineering Advisor at Harness, and Scott Davis - Senior Engineering Manager at Harness

Originaltitel: Next.js 16.4 Makes Cache Components the Recommended Default, with ensureStatic and Navigation APIsQuelle: InfoQ (InfoQ). Original öffnen