Skip to content

Report HMR latency when a Server Component changes #67699

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

Merged
merged 3 commits into from
Jul 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ function processMessage(
router.fastRefresh()
dispatcher.onRefresh()
})
reportHmrLatency(sendMessage, [])

if (process.env.__NEXT_TEST_MODE) {
if (self.__NEXT_HMR_CB) {
Expand Down
59 changes: 49 additions & 10 deletions test/development/app-hmr/hmr.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nextTestSetup } from 'e2e-utils'
import { check, waitFor } from 'next-test-utils'
import { retry, waitFor } from 'next-test-utils'

const envFile = '.env.development.local'

Expand Down Expand Up @@ -40,11 +40,10 @@ describe(`app-dir-hmr`, () => {

try {
// Should be 404 in a few seconds
await check(async () => {
await retry(async () => {
const body = await browser.elementByCss('body').text()
expect(body).toContain('404')
return 'success'
}, 'success')
})

// The new page should be rendered
const newHTML = await next.render('/folder-renamed')
Expand All @@ -61,11 +60,31 @@ describe(`app-dir-hmr`, () => {
expect(await browser.elementByCss('p').text()).toBe('mac')
await next.patchFile(envFile, 'MY_DEVICE="ipad"')

const logs = await browser.log()
await retry(async () => {
expect(logs).toEqual(
expect.arrayContaining([
expect.objectContaining({
message: '[Fast Refresh] rebuilding',
source: 'log',
}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is how it's done! 🤌

])
)
})

try {
await check(async () => {
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('ipad')
return 'success'
}, /success/)
})

expect(logs).toEqual(
expect.arrayContaining([
expect.objectContaining({
message: expect.stringContaining('[Fast Refresh] done in'),
source: 'log',
}),
])
)
} finally {
await next.patchFile(envFile, envContent)
}
Expand All @@ -77,11 +96,31 @@ describe(`app-dir-hmr`, () => {
expect(await browser.elementByCss('p').text()).toBe('mac')
await next.patchFile(envFile, 'MY_DEVICE="ipad"')

const logs = await browser.log()
await retry(async () => {
expect(logs).toEqual(
expect.arrayContaining([
expect.objectContaining({
message: '[Fast Refresh] rebuilding',
source: 'log',
}),
])
)
})

try {
await check(async () => {
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('ipad')
return 'success'
}, /success/)
})

expect(logs).toEqual(
expect.arrayContaining([
expect.objectContaining({
message: expect.stringContaining('[Fast Refresh] done in'),
source: 'log',
}),
])
)
} finally {
await next.patchFile(envFile, envContent)
}
Expand Down
Loading