Commit 1d121e9a authored by devjiwonchoi's avatar devjiwonchoi

Use globalThis flag instead of render side-effect for recovery test

The module-scoped `hasThrown` variable flipped during render, which is
fragile if React re-renders multiple times. Use a `globalThis` flag
toggled via a route handler so the test explicitly controls recovery.

https://github.com/vercel/next.js/pull/89685#discussion_r2854286441
parent a1d98a72
...@@ -9,14 +9,10 @@ export default function Page() { ...@@ -9,14 +9,10 @@ export default function Page() {
) )
} }
let hasThrown = false
async function PageImpl() { async function PageImpl() {
// Throw only during the runtime
await connection() await connection()
if (!hasThrown) { if (!globalThis.__nextTestRecover) {
hasThrown = true
throw new Error('this is a test') throw new Error('this is a test')
} }
......
export function GET(request) {
const enabled = request.nextUrl.searchParams.get('enabled') !== 'false'
globalThis.__nextTestRecover = enabled
return new Response('ok')
}
...@@ -424,12 +424,18 @@ describe('app-dir - errors', () => { ...@@ -424,12 +424,18 @@ describe('app-dir - errors', () => {
: 'An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.' : 'An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.'
) )
// Signal the server to stop throwing before retrying
await next.fetch('/server-component/recover/set-recover')
await browser await browser
.elementByCss('#retry') .elementByCss('#retry')
.click() .click()
.waitForElementByCss('#recover') .waitForElementByCss('#recover')
expect(await browser.elementByCss('#recover').text()).toBe('Recovered') expect(await browser.elementByCss('#recover').text()).toBe('Recovered')
// Restore error state for subsequent runs
await next.fetch('/server-component/recover/set-recover?enabled=false')
}) })
it('should recover Client Component error after unstable_retry', async () => { it('should recover Client Component error after unstable_retry', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment