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

Improve the readability of full page refresh error in dev mode #46634

19 changes: 18 additions & 1 deletion packages/next/src/server/dev/hot-reloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,24 @@ export default class HotReloader {
stackTrace
)?.[1]
if (file) {
fileMessage = ` when ${file} changed`
// `file` is filepath in `pages/` but it can be weird long webpack url in `app/`.
// If it's a webpack loader URL, it will start with '(app-client)/./'
if (file.startsWith('(app-client)/./')) {
const fileUrl = new URL(file, 'file://')
const cwd = process.cwd()
const modules = fileUrl.searchParams
.getAll('modules')
.map((filepath) => filepath.slice(cwd.length + 1))
.filter(
(filepath) => !filepath.startsWith('node_modules')
)

if (modules.length > 0) {
fileMessage = ` when ${modules.join(', ')} changed`
}
} else {
fileMessage = ` when ${file} changed`
}
}
}

Expand Down