From 24194719b46599c99a552d98838416f654d9418f Mon Sep 17 00:00:00 2001 From: Zack Tanner <1939140+ztanner@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:24:41 -0700 Subject: [PATCH] ensure DIO development segment errors are cleared after correcting --- .../lib/router-utils/setup-dev-bundler.ts | 4 ++ .../dynamic-io-dev-errors.test.ts | 52 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/packages/next/src/server/lib/router-utils/setup-dev-bundler.ts b/packages/next/src/server/lib/router-utils/setup-dev-bundler.ts index 228fbdc60e5d56..9fa6411fe980d5 100644 --- a/packages/next/src/server/lib/router-utils/setup-dev-bundler.ts +++ b/packages/next/src/server/lib/router-utils/setup-dev-bundler.ts @@ -289,6 +289,7 @@ async function startWatcher(opts: SetupOpts) { let enabledTypeScript = usingTypeScript let previousClientRouterFilters: any let previousConflictingPagePaths: Set = new Set() + let previouslyHadSegmentError = false wp.on('aggregated', async () => { let middlewareMatchers: MiddlewareMatcher[] | undefined @@ -569,6 +570,9 @@ 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() } } diff --git a/test/development/app-dir/dynamic-io-dev-errors/dynamic-io-dev-errors.test.ts b/test/development/app-dir/dynamic-io-dev-errors/dynamic-io-dev-errors.test.ts index 8f48695a3bbab2..4626657b7fc3e4 100644 --- a/test/development/app-dir/dynamic-io-dev-errors/dynamic-io-dev-errors.test.ts +++ b/test/development/app-dir/dynamic-io-dev-errors/dynamic-io-dev-errors.test.ts @@ -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({ @@ -67,4 +71,52 @@ describe('Dynamic IO Dev Errors', () => { expect(stack).toContain('Root [Server]') expect(stack).toContain(' (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 ( +
Hello World
+ ); + } + `, + ], + ]) + ) + + 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 ( +
Hello World
+ ); + } + ` + ) + + await retry(async () => { + assertNoRedbox(browser) + }) + + await cleanup() + }) })