hermes-agent/apps/desktop/vite.config.ts
Brooklyn Nicholson 44211f3608 feat(desktop): dev-only render + store churn counters
Adds two dev-only counters that attribute re-renders and store
notifications during an interaction, so a perf claim can be answered with
a number instead of a hunch:

  window.__RENDER_COUNTS__  what re-rendered, and why (props/state/parent)
  window.__ATOM_CHURN__     which store published it, and whether it mattered

The `wasted` column in each is the fix list — components that re-rendered
with no changed input, and stores that published a value equal to the
last one. Both are inert until start(), so idle cost is one branch per
commit and per notify.

React 19.2 removed injectProfilingHooks from react-dom, so the mark*
profiling family is unavailable and onCommitFiberRoot is the only channel
left. <Profiler> can't answer the question either: React invokes onRender
for every Profiler in a committed tree including subtrees that bailed
out, and a bailed-out subtree still reports nonzero actualDuration. This
uses bippy's didFiberRender instead. bippy over react-scan because
react-scan/lite is a thin wrapper over it while the package pulls ~217
transitive deps and floats two on latest.

main.tsx imports the entry statically above react-dom because react-dom
captures the devtools hook at module init — a late install reports
renderers=0 and observes zero commits. Production exclusion is handled by
a build-time alias to a no-op module rather than tree-shaking, since a
static side-effect import can't be eliminated.
2026-07-26 06:10:54 -05:00

95 lines
3.8 KiB
TypeScript

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import path from 'path'
import fs from 'fs'
// `hgui` symlinks a worktree's node_modules to the main checkout. Vite realpaths
// those before enforcing server.fs.allow, so codicon/font assets resolve outside
// the worktree root and 404. Whitelist the real node_modules locations.
const real = (p: string): string | null => {
try {
return fs.realpathSync(p)
} catch {
return null
}
}
const fsAllow = [
...new Set(
[
path.resolve(__dirname, '../..'),
real(path.resolve(__dirname, 'node_modules')),
real(path.resolve(__dirname, '../../node_modules'))
].filter((p): p is string => p !== null)
)
]
// The dev-only render/state churn counters (src/debug) must be imported
// STATICALLY above react-dom — react-dom captures the devtools hook at module
// init, so a dynamic import lands too late and observes zero commits. A static
// side-effect import can't be tree-shaken, so instead the whole graph is
// aliased out of any non-dev build. `command === 'serve'` covers `vite dev`;
// the perf harness opts a production build back in with VITE_PERF_PROBE=1.
const debugEntry = (command: string, env: Record<string, string>) =>
command === 'serve' || env.VITE_PERF_PROBE === '1'
? path.resolve(__dirname, './src/debug/dev-only.ts')
: path.resolve(__dirname, './src/debug/dev-only.noop.ts')
export default defineConfig(({ command }) => ({
base: './',
plugins: [react(), tailwindcss()],
css: {
// Pin an explicit (empty) PostCSS config. Tailwind is handled entirely by
// `@tailwindcss/vite`, so the renderer needs no PostCSS plugins — and
// without this, Vite's `postcss-load-config` walks UP the filesystem
// looking for a stray `postcss.config.*` / `tailwind.config.*`. The desktop
// build runs from inside the user's home tree (e.g.
// `C:\Users\<name>\AppData\Local\hermes\hermes-agent\apps\desktop`), so an
// unrelated Tailwind v3 config higher up the tree gets picked up and
// reprocesses our v4 stylesheet, failing the build with
// "`@layer base` is used but no matching `@tailwind base` directive is
// present." Pinning the config makes the build hermetic.
postcss: { plugins: [] }
},
build: {
// Keep desktop packaging stable: Shiki ships many dynamic chunks by
// default, and electron-builder can OOM scanning thousands of files.
// Collapsing to a single chunk is intentional, so the renderer bundle is
// large by design (~22 MB). Raise the warning ceiling above that so the
// cosmetic "chunk larger than 500 kB" nag stays quiet, while still acting
// as a regression alarm if the bundle balloons well past today's size.
chunkSizeWarningLimit: 25000,
rolldownOptions: {
output: {
codeSplitting: false
}
}
},
resolve: {
alias: {
'@/debug/dev-only': debugEntry(command, process.env as Record<string, string>),
'@': path.resolve(__dirname, './src'),
'@hermes/plugin-sdk': path.resolve(__dirname, './src/sdk/index.ts'),
'@hermes/shared/billing': path.resolve(__dirname, '../shared/src/billing-types.ts'),
'@hermes/shared': path.resolve(__dirname, '../shared/src'),
react: path.resolve(__dirname, '../../node_modules/react'),
'react-dom': path.resolve(__dirname, '../../node_modules/react-dom'),
'react/jsx-dev-runtime': path.resolve(__dirname, '../../node_modules/react/jsx-dev-runtime.js'),
'react/jsx-runtime': path.resolve(__dirname, '../../node_modules/react/jsx-runtime.js')
},
dedupe: ['react', 'react-dom']
},
server: {
host: '127.0.0.1',
port: 5174,
strictPort: true,
fs: {
allow: fsAllow
}
},
preview: {
host: '127.0.0.1',
port: 4174
}
}))