Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not exposing server errors in hot reloader #24331

Merged
merged 3 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/next/server/hot-reloader.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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