Unverified Commit 6d45c325 authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

fix(turbopack): Remove error overlay when issue is resolved (#62983)

### What?

Subscribe to changes of `_error` pages.

### Why?

To make the error overlay disappear when the error is fixed.

I tried skipping related entries by using `continue;` from
https://github.com/vercel/next.js/blob/5f3b13584ce87eac00f8b801c24a5de14a0a3ed9/packages/next/src/server/dev/hot-reloader-turbopack.ts#L675-L684,
but it resulted in it page being rendered in the background while error
overlay does not disappear.

We need to remove the errors from `/_error` page to make the error
overlay disappear, so I tried removing them from the map and it worked.

### How?

Closes PACK-2405
Closes PACK-2644

---------
Co-authored-by: 's avatarhrmny <8845940+ForsakenHarmony@users.noreply.github.com>
parent 0a697cf0
...@@ -66,6 +66,7 @@ export function pageBootrap(assetPrefix: string) { ...@@ -66,6 +66,7 @@ export function pageBootrap(assetPrefix: string) {
return window.location.reload() return window.location.reload()
} }
case HMR_ACTIONS_SENT_TO_BROWSER.CLIENT_CHANGES: { case HMR_ACTIONS_SENT_TO_BROWSER.CLIENT_CHANGES: {
// This is used in `../server/dev/turbopack-utils.ts`.
const isOnErrorPage = window.next.router.pathname === '/_error' const isOnErrorPage = window.next.router.pathname === '/_error'
// On the error page we want to reload the page when a page was changed // On the error page we want to reload the page when a page was changed
if (isOnErrorPage) return window.location.reload() if (isOnErrorPage) return window.location.reload()
......
...@@ -666,6 +666,7 @@ export async function createHotReloaderTurbopack( ...@@ -666,6 +666,7 @@ export async function createHotReloaderTurbopack(
const thisEntryIssues = const thisEntryIssues =
currentEntryIssues.get(appEntryKey) ?? currentEntryIssues.get(appEntryKey) ??
currentEntryIssues.get(pagesEntryKey) currentEntryIssues.get(pagesEntryKey)
if (thisEntryIssues !== undefined && thisEntryIssues.size > 0) { if (thisEntryIssues !== undefined && thisEntryIssues.size > 0) {
// If there is an error related to the requesting page we display it instead of the first error // If there is an error related to the requesting page we display it instead of the first error
return [...topLevelIssues, ...thisEntryIssues.values()].map((issue) => { return [...topLevelIssues, ...thisEntryIssues.values()].map((issue) => {
......
...@@ -890,6 +890,11 @@ export async function handlePagesErrorRoute({ ...@@ -890,6 +890,11 @@ export async function handlePagesErrorRoute({
const writtenEndpoint = await entrypoints.global.error.writeToDisk() const writtenEndpoint = await entrypoints.global.error.writeToDisk()
hooks?.handleWrittenEndpoint(key, writtenEndpoint) hooks?.handleWrittenEndpoint(key, writtenEndpoint)
hooks?.subscribeToChanges(key, false, entrypoints.global.error, () => {
// There's a special case for this in `../client/page-bootstrap.ts`.
// https://github.com/vercel/next.js/blob/08d7a7e5189a835f5dcb82af026174e587575c0e/packages/next/src/client/page-bootstrap.ts#L69-L71
return { event: HMR_ACTIONS_SENT_TO_BROWSER.CLIENT_CHANGES }
})
processIssues(currentEntryIssues, key, writtenEndpoint) processIssues(currentEntryIssues, key, writtenEndpoint)
} }
await manifestLoader.loadBuildManifest('_error') await manifestLoader.loadBuildManifest('_error')
......
...@@ -97,7 +97,7 @@ describe.each(['default', 'turbo'])( ...@@ -97,7 +97,7 @@ describe.each(['default', 'turbo'])(
if (process.env.TURBOPACK) { if (process.env.TURBOPACK) {
expect(source).toMatchInlineSnapshot(` expect(source).toMatchInlineSnapshot(`
"./pages/_app.js:2:11 "./pages/_app.js:2:11
Ecmascript file had an error Parsing ecmascript source code failed
1 | function MyApp({ Component, pageProps }) { 1 | function MyApp({ Component, pageProps }) {
> 2 | return <<Component {...pageProps} />; > 2 | return <<Component {...pageProps} />;
| ^ | ^
...@@ -186,7 +186,7 @@ describe.each(['default', 'turbo'])( ...@@ -186,7 +186,7 @@ describe.each(['default', 'turbo'])(
if (process.env.TURBOPACK) { if (process.env.TURBOPACK) {
expect(source).toMatchInlineSnapshot(` expect(source).toMatchInlineSnapshot(`
"./pages/_document.js:3:36 "./pages/_document.js:3:36
Ecmascript file had an error Parsing ecmascript source code failed
1 | import Document, { Html, Head, Main, NextScript } from 'next/document' 1 | import Document, { Html, Head, Main, NextScript } from 'next/document'
2 | 2 |
> 3 | class MyDocument extends Document {{ > 3 | class MyDocument extends Document {{
......
...@@ -1184,12 +1184,11 @@ ...@@ -1184,12 +1184,11 @@
"test/development/acceptance/ReactRefreshLogBox-app-doc.test.ts": { "test/development/acceptance/ReactRefreshLogBox-app-doc.test.ts": {
"passed": [ "passed": [
"ReactRefreshLogBox _app _document turbo empty _app shows logbox", "ReactRefreshLogBox _app _document turbo empty _app shows logbox",
"ReactRefreshLogBox _app _document turbo empty _document shows logbox" "ReactRefreshLogBox _app _document turbo empty _document shows logbox",
],
"failed": [
"ReactRefreshLogBox _app _document turbo _app syntax error shows logbox", "ReactRefreshLogBox _app _document turbo _app syntax error shows logbox",
"ReactRefreshLogBox _app _document turbo _document syntax error shows logbox" "ReactRefreshLogBox _app _document turbo _document syntax error shows logbox"
], ],
"failed": [],
"pending": [ "pending": [
"ReactRefreshLogBox _app _document default _app syntax error shows logbox", "ReactRefreshLogBox _app _document default _app syntax error shows logbox",
"ReactRefreshLogBox _app _document default _document syntax error shows logbox", "ReactRefreshLogBox _app _document default _document syntax error shows logbox",
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