chore(dev): add React profiling and focused A/B workflows

This commit is contained in:
Tunglies
2026-11-03 19:24:31 +08:00
parent 2b7b7cc0e7
commit d2c6eafc9e
18 changed files with 965 additions and 3 deletions
+32
View File
@@ -0,0 +1,32 @@
import path from 'node:path'
import { normalizePath, type Plugin } from 'vite'
export function reactDiagnostics(mode: string | undefined): Plugin[] {
if (!mode) return []
return [
{
name: 'react-diagnostics',
enforce: 'pre',
apply: 'serve',
config() {
if (mode !== 'profiler')
throw new Error(`Unknown CVR_REACT_DIAGNOSTICS mode: ${mode}`)
},
transform(code, id) {
if (id !== normalizePath(path.resolve('src/main.tsx'))) return
const open = '<React.StrictMode>'
const close = '</React.StrictMode>'
if (!code.includes(open) || !code.includes(close)) {
throw new Error('React profiling entry no longer matches main.tsx')
}
return {
code: `import { Profiler } from 'react'\nimport { recordRender } from '../scripts/react/profiler'\n${code}`
.replace(open, `<Profiler id="app" onRender={recordRender}>${open}`)
.replace(close, `${close}</Profiler>`),
map: null,
}
},
},
]
}