发表者:
Next.js 15 候选版本 (RC) 现已可供早期采用者在正式发布之前探索最新增强功能并提供反馈。
首先,使用以下命令安装候选版本:
npm安装next@rcreact@rcreact-dom@rc
有关详细文档,请访问 rc.nextjs.org/docs,直至 Next.js 15 正式发布。
安装 Babel 插件:
npm 安装 babel-plugin-react-compiler
在 next.config.js 中添加实验配置:
const nextConfig = {
实验:{
反应编译器:正确,
},
};
module.exports = nextConfig;
可选:以“选择加入”模式配置编译器:
const nextConfig = {
实验:{
反应编译器:{
编译模式: '注释',
},
},
};
module.exports = nextConfig;
基于 Next.js 14.1 的增强功能,Next.js 15 现在提供改进的水合错误视图,提供源代码见解和解决问题的建议。
Next.js 15 引入了对缓存默认值的重大更改:
const nextConfig = {
实验:{
过时时间:{
动态:30,
},
},
};
module.exports = nextConfig;
使用experimental_ppr选项,您可以针对特定布局和页面逐步采用部分预渲染,从而实现静态和动态渲染的无缝混合。
从“react”导入{Suspense};
从“@/app/ui”导入{ StaticComponent,DynamicComponent };
导出常量experimental_ppr = true;
导出默认函数 Page() {
返回 (
悬念>
>
);
}
更新 next.config.js 以逐步采用:
const nextConfig = {
实验:{
ppr: '增量',
},
};
module.exports = nextConfig;
使用 after() API 优化辅助任务而不阻塞主要响应:
从'next/server'导入{unstable_after as after};
从'@/app/utils'导入{log};
导出默认函数Layout({children}){
之后(()=> {
日志();
});
返回{孩子}>;
}
有关更改的完整列表,请查看升级指南。
深入研究 Next.js 15 RC 并让我们知道您的想法。您的反馈有助于塑造 Next.js 的未来!
随着 Next.js 15 正式发布,请继续关注更多更新!