Files
Jiwon ChoiandGitHub 9d13b676e8 Add unstable_retry() to error.js (#89685)
Extends the error components API to give better control over recovery.
Previously, the `reset()` prop only cleared the error state and
re-rendered the children. However, this only handles a temporary
rendering error.

The error can be due to data fetching or an RSC phase. In these cases,
`reset()` alone is not sufficient. Users would even need to implement
retry logic using `router.refresh()`.

Therefore, this PR adds a new `unstable_retry()` prop that calls
`router.refresh()` and `reset()` within a `startTransition()` to provide
built-in retry logic. This feature is expected to be preferred over the
`reset()` prop. Only the cases where you'd choose `reset()` are when you
have a reason to do a sync reset without loading any new data.

Closes NAR-767
2026-02-26 21:22:27 +01:00

27 lines
455 B
JavaScript

import { Suspense } from 'react'
import { connection } from 'next/server'
export default function Page() {
return (
<Suspense>
<Container>
<Content />
</Container>
</Suspense>
)
}
function Container({ children }) {
return <div>{children}</div>
}
async function Content() {
await connection()
if (!globalThis.__nextTestRecover) {
throw new Error('this is a test')
}
return <p id="recover">Recovered</p>
}