Skip to content

Commit 2419471

Browse files
committed
ensure DIO development segment errors are cleared after correcting
1 parent 5ab28cd commit 2419471

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

packages/next/src/server/lib/router-utils/setup-dev-bundler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ async function startWatcher(opts: SetupOpts) {
289289
let enabledTypeScript = usingTypeScript
290290
let previousClientRouterFilters: any
291291
let previousConflictingPagePaths: Set<string> = new Set()
292+
let previouslyHadSegmentError = false
292293

293294
wp.on('aggregated', async () => {
294295
let middlewareMatchers: MiddlewareMatcher[] | undefined
@@ -569,6 +570,9 @@ async function startWatcher(opts: SetupOpts) {
569570
const errorMessage = `The following pages used segment configs which are not supported with "experimental.dynamicIO" and must be removed to build your application:\n${pagesWithIncompatibleSegmentConfigs.join('\n')}\n`
570571
Log.error(errorMessage)
571572
hotReloader.setHmrServerError(new Error(errorMessage))
573+
previouslyHadSegmentError = true
574+
} else if (previouslyHadSegmentError) {
575+
hotReloader.clearHmrServerError()
572576
}
573577
}
574578

test/development/app-dir/dynamic-io-dev-errors/dynamic-io-dev-errors.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { nextTestSetup } from 'e2e-utils'
22
import {
33
assertHasRedbox,
4+
assertNoRedbox,
45
getRedboxCallStack,
56
getRedboxDescription,
67
hasErrorToast,
78
retry,
89
waitForAndOpenRuntimeError,
10+
getRedboxSource,
911
} from 'next-test-utils'
12+
import { sandbox } from 'development-sandbox'
13+
import { outdent } from 'outdent'
1014

1115
describe('Dynamic IO Dev Errors', () => {
1216
const { next } = nextTestSetup({
@@ -67,4 +71,52 @@ describe('Dynamic IO Dev Errors', () => {
6771
expect(stack).toContain('Root [Server]')
6872
expect(stack).toContain('<anonymous> (2:1)')
6973
})
74+
75+
it('should clear segment errors after correcting them', async () => {
76+
const { cleanup, session, browser } = await sandbox(
77+
next,
78+
new Map([
79+
[
80+
'app/page.tsx',
81+
outdent`
82+
export const revalidate = 10
83+
export default function Page() {
84+
return (
85+
<div>Hello World</div>
86+
);
87+
}
88+
`,
89+
],
90+
])
91+
)
92+
93+
await assertHasRedbox(browser)
94+
const redbox = {
95+
description: await getRedboxDescription(browser),
96+
source: await getRedboxSource(browser),
97+
}
98+
99+
expect(redbox.description).toMatchInlineSnapshot(`"Failed to compile"`)
100+
expect(redbox.source).toMatchInlineSnapshot(`
101+
"The following pages used segment configs which are not supported with "experimental.dynamicIO" and must be removed to build your application:
102+
/: revalidate"
103+
`)
104+
105+
await session.patch(
106+
'app/page.tsx',
107+
outdent`
108+
export default function Page() {
109+
return (
110+
<div>Hello World</div>
111+
);
112+
}
113+
`
114+
)
115+
116+
await retry(async () => {
117+
assertNoRedbox(browser)
118+
})
119+
120+
await cleanup()
121+
})
70122
})

0 commit comments

Comments
 (0)