Skip to content

Commit e463adf

Browse files
authored
feat: enable React profiling build for dogfood (#23354)
1 parent d126a86 commit e463adf

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

.github/workflows/ci.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,12 @@ jobs:
12171217
EV_CERTIFICATE_PATH: /tmp/ev_cert.pem
12181218
GCLOUD_ACCESS_TOKEN: ${{ steps.gcloud_auth.outputs.access_token }}
12191219
JSIGN_PATH: /tmp/jsign-6.0.jar
1220+
# Enable React profiling build and discoverable source maps
1221+
# for the dogfood deployment (dev.coder.com). This also
1222+
# applies to release/* branch builds, but those still
1223+
# produce coder-preview images, not release images.
1224+
# Release images are built by release.yaml (no profiling).
1225+
CODER_REACT_PROFILING: "true"
12201226

12211227
# Free up disk space before building Docker images. The preceding
12221228
# Build step produces ~2 GB of binaries and packages, the Go build

site/vite.config.mts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import type { PluginOption } from "vite";
77
import checker from "vite-plugin-checker";
88
import { 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+
1018
const 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

Comments
 (0)