Skip to content

Commit

Permalink
Report HMR latency when a Server Component changes (#67699)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jul 12, 2024
1 parent a4a628c commit 2621746
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
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',
}),
])
)
})

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

0 comments on commit 2621746

Please sign in to comment.