rsnext/errors/ppr-caught-error.mdx
Sebastian Markbåge 2f68e62d30
Reword PPR caught bail out to avoid "postpone" terminology (#58223)
The "postpone" terminology is internal to React and can be used for more
things than just this. It's also a mechanism we may or may not rely on.

---------

Co-authored-by: Zack Tanner <zacktanner@gmail.com>
2023-11-08 17:08:24 -05:00

27 lines
1.1 KiB
Text

---
title: Static Bail Out Caught
---
## Why This Error Occurred
When Partial Prerendering (PPR) is enabled, using APIs that opt into Dynamic Rendering like `cookies`, `headers`, or `fetch` (such as with `cache: 'no-store'` or `revalidate: 0`) will cause React to throw a special error object to know which part of the page cannot be statically generated - while still letting the rest of it be partially static. If you catch this error, it is not safe for us to generate any static data, and your build will fail.
## Possible Ways to Fix It
- Ensure that you are not wrapping Next.js APIs that opt into dynamic rendering in a `try/catch` block.
- If you do wrap these APIs in a try/catch, make sure you re-throw the original error so it can be caught by Next.js.
- Alternatively, insert [`unstable_noStore()`](docs/app/api-reference/functions/unstable_noStore) before the try/catch.
```js
import { unstable_noStore } from 'next/cache'
async function fetchData() {
unstable_noStore() // opt out before we even get to the try/catch
try {
const response = await fetch(url);
...
} catch (x) {
...
}
}
```