Skip to content

Commit

Permalink
ensure DIO development segment errors are cleared after correcting (v…
Browse files Browse the repository at this point in the history
…ercel#71811)

This clears segment config errors that are corrected in development mode
when using `dynamicIO`.
  • Loading branch information
ztanner authored and stipsan committed Nov 6, 2024
1 parent 0c0fca4 commit 3260542
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
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,15 +1,19 @@
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({
const { next, isTurbopack } = nextTestSetup({
files: __dirname,
})

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

// `setHmrServerError` is not currently implemented in Turbopack
// we will need to enable this after it gets implemented.
if (!isTurbopack) {
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 3260542

Please sign in to comment.