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

Remove stack trace from full reload warning #43453

Merged
merged 5 commits into from Nov 28, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions errors/fast-refresh-reload.md
@@ -0,0 +1,17 @@
# Fast Refresh had to perform full reload

#### Why This Error Occurred

Fast Refresh had to perform a full reload when you edited a file. It may be because:

- The file you're editing might have other exports in addition to a React component.
- Your React component is an anonymous function.

#### Possible Ways to Fix It

- Move your other exports to a separate file.
- Use a named function for your React component.

### Useful Links

[Fast Refresh documentation](https://nextjs.org/docs/basic-features/fast-refresh)
4 changes: 4 additions & 0 deletions errors/manifest.json
Expand Up @@ -769,6 +769,10 @@
{
"title": "app-dir-dynamic-href",
"path": "/errors/app-dir-dynamic-href.md"
},
{
"title": "fast-refresh-reload",
"path": "/errors/fast-refresh-reload.md"
}
]
}
Expand Down
1 change: 1 addition & 0 deletions packages/next/client/dev/error-overlay/hot-dev-client.js
Expand Up @@ -398,6 +398,7 @@ function performFullReload(err) {
JSON.stringify({
event: 'client-full-reload',
stackTrace,
hadRuntimeError: !!hadRuntimeError,
})
)

Expand Down
29 changes: 23 additions & 6 deletions packages/next/server/dev/hot-reloader.ts
Expand Up @@ -357,16 +357,33 @@ export default class HotReloader {
break
}
case 'client-full-reload': {
const { event, stackTrace, hadRuntimeError } = payload

traceChild = {
name: payload.event,
attrs: { stackTrace: payload.stackTrace ?? '' },
name: event,
attrs: { stackTrace: stackTrace ?? '' },
}

if (hadRuntimeError) {
Log.warn(
`Fast Refresh had to perform a full reload due to a runtime error.`
)
break
}

let fileMessage = ''
if (stackTrace) {
const file = /Aborted because (.+) is not accepted/.exec(
stackTrace
)?.[1]
if (file) {
fileMessage = ` when ${file} changed`
}
}

Log.warn(
'Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/basic-features/fast-refresh#how-it-works'
`Fast Refresh had to perform a full reload${fileMessage}. Read more: https://nextjs.org/docs/messages/fast-refresh-reload`
)
if (payload.stackTrace) {
console.warn(payload.stackTrace)
}
break
}
default: {
Expand Down
32 changes: 12 additions & 20 deletions test/development/basic/hmr.test.ts
Expand Up @@ -778,10 +778,11 @@ describe('basic HMR', () => {
next.appPort,
`/hmr/anonymous-page-function`
)
const cliWarning =
'Fast Refresh had to perform a full reload when ./pages/hmr/anonymous-page-function.js changed. Read more: https://nextjs.org/docs/messages/fast-refresh-reload'

expect(await browser.elementByCss('p').text()).toBe('hello world')
expect(next.cliOutput.slice(start)).not.toContain(
'Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/basic-features/fast-refresh#how-it-works'
)
expect(next.cliOutput.slice(start)).not.toContain(cliWarning)

const currentFileContent = await next.readFile(
'./pages/hmr/anonymous-page-function.js'
Expand All @@ -799,13 +800,8 @@ describe('basic HMR', () => {
'hello world!!!'
)

// CLI warning and stacktrace
expect(next.cliOutput.slice(start)).toContain(
'Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/basic-features/fast-refresh#how-it-works'
)
expect(next.cliOutput.slice(start)).toContain(
'Error: Aborted because ./pages/hmr/anonymous-page-function.js is not accepted'
)
// CLI warning
expect(next.cliOutput.slice(start)).toContain(cliWarning)

// Browser warning
const browserLogs = await browser.log()
Expand All @@ -821,13 +817,14 @@ describe('basic HMR', () => {
it('should warn about full reload in cli output - runtime-error', async () => {
const start = next.cliOutput.length
const browser = await webdriver(next.appPort, `/hmr/runtime-error`)
const cliWarning =
'Fast Refresh had to perform a full reload due to a runtime error.'

await check(
() => getRedboxHeader(browser),
/ReferenceError: whoops is not defined/
)
expect(next.cliOutput.slice(start)).not.toContain(
'Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/basic-features/fast-refresh#how-it-works'
)
expect(next.cliOutput.slice(start)).not.toContain(cliWarning)

const currentFileContent = await next.readFile(
'./pages/hmr/runtime-error.js'
Expand All @@ -842,13 +839,8 @@ describe('basic HMR', () => {
'whoops'
)

// CLI warning and stacktrace
expect(next.cliOutput.slice(start)).toContain(
'Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/basic-features/fast-refresh#how-it-works'
)
expect(next.cliOutput.slice(start)).not.toContain(
'Error: Aborted because ./pages/runtime-error.js is not accepted'
)
// CLI warning
expect(next.cliOutput.slice(start)).toContain(cliWarning)

// Browser warning
const browserLogs = await browser.log()
Expand Down