Skip to content

Commit

Permalink
Improve the readability of full page refresh error in dev mode (#46634)
Browse files Browse the repository at this point in the history
Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
jankaifer and ijjk committed Mar 7, 2023
1 parent 533748d commit 70d6438
Showing 1 changed file with 18 additions and 1 deletion.
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

0 comments on commit 70d6438

Please sign in to comment.