Skip to content

Commit 6cd1c87

Browse files
authoredApr 22, 2021
Fix not exposing server errors in hot reloader (#24331)
Fixes #24056. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. ## Documentation / Examples - [ ] Make sure the linting passes
1 parent 85d87a3 commit 6cd1c87

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
 

‎packages/next/server/hot-reloader.ts

+14
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,20 @@ export default class HotReloader {
612612

613613
// If none were found we still have to show the other errors
614614
return this.stats.compilation.errors
615+
} else if (this.serverStats?.hasErrors()) {
616+
const { compilation } = this.serverStats
617+
const failedPages = erroredPages(compilation)
618+
619+
// If there is an error related to the requesting page we display it instead of the first error
620+
if (
621+
failedPages[normalizedPage] &&
622+
failedPages[normalizedPage].length > 0
623+
) {
624+
return failedPages[normalizedPage]
625+
}
626+
627+
// If none were found we still have to show the other errors
628+
return this.serverStats.compilation.errors
615629
}
616630

617631
return []

‎test/acceptance/ReactRefreshLogBox.dev.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,30 @@ test('_document top level error shows logbox', async () => {
13811381
await cleanup()
13821382
})
13831383

1384+
test('server-side only compilation errors', async () => {
1385+
const [session, cleanup] = await sandbox()
1386+
1387+
await session.patch(
1388+
'pages/index.js',
1389+
`
1390+
import myLibrary from 'my-non-existent-library'
1391+
export async function getStaticProps() {
1392+
return {
1393+
props: {
1394+
result: myLibrary()
1395+
}
1396+
}
1397+
}
1398+
export default function Hello(props) {
1399+
return <h1>{props.result}</h1>
1400+
}
1401+
`
1402+
)
1403+
1404+
expect(await session.hasRedbox(true)).toBe(true)
1405+
await cleanup()
1406+
})
1407+
13841408
test('empty _app shows logbox', async () => {
13851409
const [session, cleanup] = await sandbox(
13861410
undefined,

0 commit comments

Comments
 (0)
Please sign in to comment.