@@ -7,6 +7,14 @@ import type { PluginOption } from "vite";
77import checker from "vite-plugin-checker" ;
88import { defineConfig } from "vitest/config" ;
99
10+ // Enable the React profiling build and discoverable source maps for
11+ // internal deployments (e.g. dogfood). The profiling build swaps
12+ // react-dom/client for react-dom/profiling, which keeps production
13+ // optimizations but leaves the <Profiler> onRender callback and
14+ // React Performance Tracks instrumentation intact. The overhead is
15+ // ~13% on the react-dom chunk size.
16+ const isProfilingBuild = process . env . CODER_REACT_PROFILING === "true" ;
17+
1018const plugins : PluginOption [ ] = [
1119 react ( {
1220 babel : {
@@ -42,7 +50,7 @@ export default defineConfig({
4250 build : {
4351 outDir : path . resolve ( __dirname , "./out" ) ,
4452 emptyOutDir : false , // We need to keep the /bin folder and GITKEEP files
45- sourcemap : "hidden" ,
53+ sourcemap : isProfilingBuild ? true : "hidden" ,
4654 rollupOptions : {
4755 input : {
4856 index : path . resolve ( __dirname , "./index.html" ) ,
@@ -209,6 +217,15 @@ export default defineConfig({
209217 } ,
210218 resolve : {
211219 alias : {
220+ // In profiling builds, swap the production react-dom client
221+ // bundle for the profiling variant so that <Profiler>
222+ // onRender receives actual timing data.
223+ // Note: react-dom/profiling is a superset of react-dom/client
224+ // (16 vs 3 exports). If a future React major changes this
225+ // relationship, the alias may need updating.
226+ ...( isProfilingBuild
227+ ? { "react-dom/client" : "react-dom/profiling" }
228+ : { } ) ,
212229 App : path . resolve ( __dirname , "./src/App" ) ,
213230 api : path . resolve ( __dirname , "./src/api" ) ,
214231 components : path . resolve ( __dirname , "./src/components" ) ,
0 commit comments