nextjs runtime_error ai_generated true

错误:缺少 Suspense 边界。页面使用了流式渲染,但没有 Suspense 边界包裹异步组件。

Error: Missing Suspense boundary. The page uses streaming but no Suspense boundary wraps the async component.

ID: nextjs/suspense-boundary-missing-streaming

其他格式: JSON · Markdown 中文 · English
93%修复率
87%置信度
1证据数
2024-01-15首次发现

版本兼容性

版本状态引入弃用备注
[email protected] active
[email protected] active

根因分析

一个使用流式渲染的异步服务器组件(例如,通过等待一个 promise)没有被包裹在 Suspense 边界中,导致 Next.js 在流式渲染期间无法渲染回退 UI。

English

An async server component that uses streaming (e.g., by awaiting a promise) is not wrapped in a Suspense boundary, causing Next.js to fail to render the fallback UI during streaming.

generic

官方文档

https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming

解决方案

  1. Wrap the async component in a Suspense boundary in the parent layout or page.
  2. Use the loading.js file at the same route segment level to provide a default Suspense boundary.

无效尝试

常见但无效的做法:

  1. 90% 失败

    This converts the component to a client component, which cannot use async/await at the top level, causing a different error (async/await not supported in Client Components).

  2. 60% 失败

    This changes the data fetching pattern and may break server-side rendering benefits. It also requires converting to a client component, which may not be desired.