InfoQ

Next.js 16.4 Makes Cache Components the Recommended Default, with ensureStatic and Navigation APIs

8.5内容质量
Next.js 16.4 Makes Cache Components the Recommended Default, with ensureStatic and Navigation APIs

TL;DR · AI 摘要

Next.js 16.4将缓存组件设为默认,通过ensureStatic和Navigation API优化性能,集成React 19.3并改进Turbopack压缩。

核心要点

  • Next.js 16.4默认启用cacheComponents和partialPrefetching配置
  • ensureStatic API可阻止动态内容意外进入静态页面
  • Turbopack压缩减少20-25%磁盘空间占用

结构提纲

按章节快速跳转。

  1. Next.js 16.4发布重大更新,改变缓存组件默认行为并引入新API。

  2. 从Next.js 16.4开始,所有新项目默认启用cacheComponents配置。

  3. 该API通过构建时校验防止动态内容污染静态页面。

  4. 新API允许延迟加载缓存内容,优化导航性能。

  5. ›Turbopack优化

    Zstandard压缩减少磁盘空间占用,HMR优化提升开发体验。

  6. ·React 19.3集成

    引入稳定视图过渡、Fragment Refs等新特性。

思维导图

用一张图看清主题之间的关系。

查看大纲文本(无障碍 / 无 JS 友好)
  • Next.js 16.4更新
    • 缓存组件优化
      • 默认启用cacheComponents
      • ensureStatic校验机制
    • 新API
      • navigation()延迟加载
      • prefetch()优化预取
    • 性能提升
      • Turbopack压缩优化
      • React 19.3特性集成

金句 / Highlights

值得收藏与分享的关键句。

#Next.js#前端#缓存#React
打开原文

Next.js 16.4 将缓存组件设为推荐默认选项,引入 ensureStatic 和导航 API - InfoQ

InfoQ 首页 News Next.js 16.4 将缓存组件设为推荐默认选项,引入 ensureStatic 和导航 API

Web 开发

InfoQ 认证 AI 工程师计划(在线,1月9日):推动重要 AI 决策向前发展。

Next.js 16.4 将缓存组件设为推荐默认选项,引入 ensureStatic 和导航 API

2026年11月30日 3分钟阅读

作者:

  • Daniel Curtis

#### 关注我们

YouTube

232K 粉丝

LinkedIn

26K 粉丝

Instagram

新

RSS

19K 读者

X

57.1k 粉丝

Facebook

21K 赞

Bluesky

收听本文 -

0:00

音频准备就绪

您的浏览器不支持音频元素。

正常

1.25x

1.5x

喜欢

新下拉阅读列表

  • 阅读列表

Vercel 于 2026 年 10 月 6 日发布了 Next.js 16.4,这次更新既是功能上的变革,也是推荐策略的转变。从 16.0 版本引入的可选缓存组件(Cache Components)现在已成为团队建议所有应用采用的默认方案,并将在 Next.js 17 中成为框架的默认设置。

通过 create-next-app 创建的新项目从一开始就默认在 next.config.ts 中启用 cacheComponents: true 和 partialPrefetching: true。如 BuildMVPFast 所说,"你的 next.config.ts 现在多了两行你未曾请求的配置"。现有应用需要手动设置:

code
const nextConfig: NextConfig = {
 cacheComponents: true,
 partialPrefetching: true,
};

两个新 API 的引入旨在保持缓存组件的可预测性。从路由或布局导出的 ensureStatic 方法会在动态内容意外进入页面外壳、预取或完整导航时导致构建失败。CODERCOPS 博客的 Abhishek Gupta 将其描述为"一种在代码审查时而非发票上阻止成本回归的低成本方式",并建议先在根布局中应用该方法,再在确实需要动态数据的页面中放宽限制。

第二个新增功能是来自 next/cache 的 navigation() 和 prefetch() 函数,它们会从预取中排除缓存内容,并延迟到真实导航时加载。Gupta 将 navigation() 称为"此次发布中最实用的新增功能",特别适用于收件箱式页面,此前预取每个可见链接都会通过网络加载完整邮件线程:

code
import { navigation } from 'next/cache';
async function Thread({ id }) {
 await navigation();
 const thread = await getThread(id);
 // ...
}

得益于 Zstandard 压缩,Turbopack 的磁盘缓存减少了 20% 到 25% 的存储空间占用,懒加载服务器 HMR 仅重新编译当前视图中的路由,生产构建的 CSS Module 类名更短且导出名称经过混淆。此次发布引入了 React 19.3,包含稳定的视图过渡(View Transitions)、Fragment Refs 和新的 browser() API,而 React 编译器的实验性 Rust 移植版本在 Turbopack 团队调整内存分配后,内存使用量减少了 30%,编译时间缩短了 15%。

此次发布进一步深化了代理驱动的工作流。新的 npx next@canary 升级命令 --agent=latest 会将版本匹配的迁移指南、代码转换工具和验证步骤传递给编码代理,而实验性功能 experimental.agentUpgrade 会在有相关安全更新或次要版本发布时,从 next dev 提示开发者。可选的实验性功能 experimental.agentFeedback 标志允许代理在发送任何内容前,为框架问题准备待审的报告草稿。

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:

关于使用 OpenNext 自托管的一些注意事项,似乎会稍微降低页面性能,因此建议自行测试,而不是直接假设其可以正常工作。补充说明:进一步说明的话,我认为 Next 服务器试图在服务器端渲染应用壳,但 OpenNext 并不像 Vercel 提供的那样支持边缘缓存和流续传功能。

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 是由 Vercel 开发和维护的开源 React 框架。它通过基于文件的路由、服务端渲染和 App Router 的服务器组件扩展了 React,被广泛用于从静态站点到大规模动态应用的各种场景。

main wrapper for authors section

About the Author

section title

main wrapper for each author

#### Daniel Curtis

Show more

Show less

#### This content is in the Web Development topic

##### Related Topics:

  • Development
  • TypeScript
  • Web Development
  • JavaScript
  • Caching
  • Next.js
  • Related Editorial
  • Related Sponsors AI Security Playbook: Move Faster with AI, Without Compromising Security
  • Related Sponsor Equal Experts helps organizations harness AI, modernize technology, and build better software through expert engineering, collaboration, and innovative delivery practices. Learn more .

The InfoQ Newsletter

A round-up of last week’s content on InfoQ sent out every Tuesday. Join a community of over 250,000 senior developers. View an example

We protect your privacy.