Skip to content

Commit

Permalink
Add telemetry for React Compiler usage (#68079)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jul 29, 2024
1 parent 33c91d9 commit cc66c59
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/next/src/telemetry/events/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type EventCliSessionStarted = {
pagesDir: boolean | null
staticStaleTime: number | null
dynamicStaleTime: number | null
reactCompiler: boolean
reactCompilerCompilationMode: string | null
reactCompilerPanicThreshold: string | null
}

function hasBabelConfig(dir: string): boolean {
Expand Down Expand Up @@ -83,6 +86,9 @@ export function eventCliSession(
| 'reactStrictMode'
| 'staticStaleTime'
| 'dynamicStaleTime'
| 'reactCompiler'
| 'reactCompilerCompilationMode'
| 'reactCompilerPanicThreshold'
>
): { eventName: string; payload: EventCliSessionStarted }[] {
// This should be an invariant, if it fails our build tooling is broken.
Expand Down Expand Up @@ -126,6 +132,15 @@ export function eventCliSession(
pagesDir: event.pagesDir,
staticStaleTime: nextConfig.experimental.staleTimes?.static ?? null,
dynamicStaleTime: nextConfig.experimental.staleTimes?.dynamic ?? null,
reactCompiler: Boolean(nextConfig.experimental.reactCompiler),
reactCompilerCompilationMode:
typeof nextConfig.experimental.reactCompiler !== 'boolean'
? nextConfig.experimental.reactCompiler?.compilationMode ?? null
: null,
reactCompilerPanicThreshold:
typeof nextConfig.experimental.reactCompiler !== 'boolean'
? nextConfig.experimental.reactCompiler?.panicThreshold ?? null
: null,
}
return [{ eventName: EVENT_VERSION, payload }]
}
5 changes: 5 additions & 0 deletions test/integration/telemetry/next.config.reactCompiler-base
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
reactCompiler: true
}
}
8 changes: 8 additions & 0 deletions test/integration/telemetry/next.config.reactCompiler-options
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
experimental: {
reactCompiler: {
compilationMode: 'annotation',
panicThreshold: 'CRITICAL_ERRORS'
}
}
}
84 changes: 84 additions & 0 deletions test/integration/telemetry/test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,90 @@ describe('config telemetry', () => {
invocationCount: 1,
})
})

it('emits telemetry for default React Compiler options', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})

try {
const event = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()

expect(event).toMatch(/"reactCompiler": false/)
expect(event).toMatch(/"reactCompilerCompilationMode": null/)
expect(event).toMatch(/"reactCompilerPanicThreshold": null/)
} catch (err) {
require('console').error('failing stderr', stderr, err)
throw err
}
})

it('emits telemetry for enabled React Compiler', async () => {
await fs.rename(
path.join(appDir, 'next.config.reactCompiler-base'),
path.join(appDir, 'next.config.js')
)

let stderr
try {
const app = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
stderr = app.stderr
const event = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()

expect(event).toMatch(/"reactCompiler": true/)
expect(event).toMatch(/"reactCompilerCompilationMode": null/)
expect(event).toMatch(/"reactCompilerPanicThreshold": null/)
} catch (err) {
require('console').error('failing stderr', stderr, err)
throw err
} finally {
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.reactCompiler-base')
)
}
})

it('emits telemetry for configured React Compiler options', async () => {
await fs.rename(
path.join(appDir, 'next.config.reactCompiler-options'),
path.join(appDir, 'next.config.js')
)

let stderr
try {
const app = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
stderr = app.stderr
const event = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()

expect(event).toMatch(/"reactCompiler": true/)
expect(event).toMatch(/"reactCompilerCompilationMode": "annotation"/)
expect(event).toMatch(
/"reactCompilerPanicThreshold": "CRITICAL_ERRORS"/
)
} catch (err) {
require('console').error('failing stderr', stderr, err)
throw err
} finally {
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.reactCompiler-options')
)
}
})
}
)
})

0 comments on commit cc66c59

Please sign in to comment.