Skip to content

Commit 3c2670d

Browse files
authored
1 parent 2af3d06 commit 3c2670d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

packages/next/src/lib/require-instrumentation-client.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
* The `private-next-instrumentation-client` module is automatically aliased to
55
* the `instrumentation-client.ts` file in the project root by webpack or turbopack.
66
*/
7-
87
if (process.env.__NEXT_EXPERIMENTAL_CLIENT_INSTRUMENTATION_HOOK) {
9-
require('private-next-instrumentation-client')
8+
if (process.env.NODE_ENV === 'development') {
9+
const startTime = performance.now()
10+
require('private-next-instrumentation-client')
11+
const endTime = performance.now()
12+
console.log(
13+
`[Client Instrumentation Hook] executed in ${(endTime - startTime).toFixed(0)}ms (Note: Code download overhead is not included in this measurement)`
14+
)
15+
} else {
16+
require('private-next-instrumentation-client')
17+
}
1018
}

test/e2e/instrumentation-client-hook/instrumentation-client-hook.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Instrumentation Client Hook', () => {
2020

2121
testCases.forEach(({ name, appDir }) => {
2222
describe(name, () => {
23-
const { next } = nextTestSetup({
23+
const { next, isNextDev } = nextTestSetup({
2424
files: path.join(__dirname, appDir),
2525
})
2626

@@ -35,6 +35,11 @@ describe('Instrumentation Client Hook', () => {
3535
expect(instrumentationTime).toBeDefined()
3636
expect(hydrationTime).toBeDefined()
3737
expect(instrumentationTime).toBeLessThan(hydrationTime)
38+
expect(
39+
(await browser.log()).some((log) =>
40+
log.message.startsWith('[Client Instrumentation Hook]')
41+
)
42+
).toBe(isNextDev)
3843
})
3944
})
4045
})

0 commit comments

Comments
 (0)