mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
This PR adds `unstable_catchError()` API for a granular custom error boundary. The error component generated by this API is not a true component format, as the wrapper provides additional args. Therefore, the API is a function call by design rather than a boundary component to avoid merging the `errorInfo` with the user-provided props from the wrapper. This API works for both the App/Pages Router. However, `retry()` is not allowed in Pages Router as it depends on `router.refresh()`, and will throw. Also, it's exported from `next/error` as there was already an `Error` component for the [Pages Router](https://nextjs.org/docs/pages/building-your-application/routing/custom-error#reusing-the-built-in-error-page). ### DevTools <img width="508" height="90" alt="CleanShot 2026-03-13 at 03 02 46@2x" src="https://github.com/user-attachments/assets/8b79b1f6-877d-4901-99f7-6a2b4d3e34fe" /> Docs to follow up: https://github.com/vercel/next.js/pull/89847 Closes NAR-768 --------- Co-authored-by: Josh Story <[email protected]>
24 lines
374 B
TypeScript
24 lines
374 B
TypeScript
import { Suspense } from 'react'
|
|
import { connection } from 'next/server'
|
|
|
|
export default function Page() {
|
|
return (
|
|
<Suspense>
|
|
<PageImpl />
|
|
</Suspense>
|
|
)
|
|
}
|
|
|
|
let hasThrown = false
|
|
|
|
async function PageImpl() {
|
|
await connection()
|
|
|
|
if (!hasThrown) {
|
|
hasThrown = true
|
|
throw new Error('this is a test')
|
|
}
|
|
|
|
return <p id="recover">Recovered</p>
|
|
}
|