Skip to content

Commit

Permalink
Fix not exposing server errors in hot reloader (#24331)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shuding committed Apr 22, 2021
1 parent 85d87a3 commit 6cd1c87
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/next/server/hot-reloader.ts
Expand Up @@ -612,6 +612,20 @@ export default class HotReloader {

// If none were found we still have to show the other errors
return this.stats.compilation.errors
} else if (this.serverStats?.hasErrors()) {
const { compilation } = this.serverStats
const failedPages = erroredPages(compilation)

// If there is an error related to the requesting page we display it instead of the first error
if (
failedPages[normalizedPage] &&
failedPages[normalizedPage].length > 0
) {
return failedPages[normalizedPage]
}

// If none were found we still have to show the other errors
return this.serverStats.compilation.errors
}

return []
Expand Down
24 changes: 24 additions & 0 deletions test/acceptance/ReactRefreshLogBox.dev.test.js
Expand Up @@ -1381,6 +1381,30 @@ test('_document top level error shows logbox', async () => {
await cleanup()
})

test('server-side only compilation errors', async () => {
const [session, cleanup] = await sandbox()

await session.patch(
'pages/index.js',
`
import myLibrary from 'my-non-existent-library'
export async function getStaticProps() {
return {
props: {
result: myLibrary()
}
}
}
export default function Hello(props) {
return <h1>{props.result}</h1>
}
`
)

expect(await session.hasRedbox(true)).toBe(true)
await cleanup()
})

test('empty _app shows logbox', async () => {
const [session, cleanup] = await sandbox(
undefined,
Expand Down

0 comments on commit 6cd1c87

Please sign in to comment.