Skip to content

Commit

Permalink
ensure DIO development segment errors are cleared after correcting
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Oct 24, 2024
1 parent 5ab28cd commit afd20d6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ async function startWatcher(opts: SetupOpts) {
let enabledTypeScript = usingTypeScript
let previousClientRouterFilters: any
let previousConflictingPagePaths: Set<string> = new Set()
let previouslyHadSegmentError = false

wp.on('aggregated', async () => {
let middlewareMatchers: MiddlewareMatcher[] | undefined
Expand Down Expand Up @@ -569,6 +570,10 @@ async function startWatcher(opts: SetupOpts) {
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`
Log.error(errorMessage)
hotReloader.setHmrServerError(new Error(errorMessage))
previouslyHadSegmentError = true
} else if (previouslyHadSegmentError) {
hotReloader.clearHmrServerError()
previouslyHadSegmentError = false
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { nextTestSetup } from 'e2e-utils'
import {
assertHasRedbox,
assertNoRedbox,
getRedboxCallStack,
getRedboxDescription,
hasErrorToast,
retry,
waitForAndOpenRuntimeError,
getRedboxSource,
} from 'next-test-utils'
import { sandbox } from 'development-sandbox'
import { outdent } from 'outdent'

describe('Dynamic IO Dev Errors', () => {
const { next } = nextTestSetup({
Expand Down Expand Up @@ -67,4 +71,52 @@ describe('Dynamic IO Dev Errors', () => {
expect(stack).toContain('Root [Server]')
expect(stack).toContain('<anonymous> (2:1)')
})

it('should clear segment errors after correcting them', async () => {
const { cleanup, session, browser } = await sandbox(
next,
new Map([
[
'app/page.tsx',
outdent`
export const revalidate = 10
export default function Page() {
return (
<div>Hello World</div>
);
}
`,
],
])
)

await assertHasRedbox(browser)
const redbox = {
description: await getRedboxDescription(browser),
source: await getRedboxSource(browser),
}

expect(redbox.description).toMatchInlineSnapshot(`"Failed to compile"`)
expect(redbox.source).toMatchInlineSnapshot(`
"The following pages used segment configs which are not supported with "experimental.dynamicIO" and must be removed to build your application:
/: revalidate"
`)

await session.patch(
'app/page.tsx',
outdent`
export default function Page() {
return (
<div>Hello World</div>
);
}
`
)

await retry(async () => {
assertNoRedbox(browser)
})

await cleanup()
})
})

0 comments on commit afd20d6

Please sign in to comment.