Sub topic 9
Development, production, and profiling builds
This chapter assumes you can write React function components, use useState and props, and open the browser's Elements and Console panels. It also assumes you have installed React Developer Tools and can open the Components tab. The question here is which build of your app you are debugging, because that decides what the tools can show you.
Why the build matters
React ships in more than one form. The code you run while building a feature is not the code your users download. React Developer Tools behaves differently for each, and some of its readings are only trustworthy in certain builds.
There are three cases to know:
- Development build. This is what
npm run devornpm startserves. React includes extra warnings, readable component names, and extra checks. It runs slower on purpose. - Production build. This is what
npm run buildproduces. React removes the warnings and checks, and your code is minified. It is the fastest form, but it exposes the least to the tools. - Profiling build. This is a production build with profiling hooks left in. It is nearly as fast as production and still lets the Profiler record timings.
What the extension icon tells you
The React Developer Tools icon in the browser toolbar changes color to show which build it found on the page.
| Icon | Meaning | What you can do |
|---|---|---|
| Red or orange | Development build | Full Components tab and Profiler |
| Blue | Production build | Components tab is limited, Profiler is unavailable |
| Gray | No React detected | Nothing to inspect |
Click the icon to see a short message that confirms the build type. Check it before you start measuring anything.
Why development timings mislead
The Profiler works in a development build, but the durations it reports are inflated. Development React does extra work on every render. In StrictMode, React also renders components twice to expose side effects. A component that looks slow in development may be fast for your users.
Use development builds to find out why something renders and how often. Do not use them to decide how many milliseconds a render costs. For real timings, measure a profiling build.
Making a profiling build
Production builds strip the profiling hooks by default, so the Profiler tab does nothing. You have to ask for them. With Vite, alias react-dom/client to its profiling version in vite.config.js:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig(({ mode }) => ({
plugins: [react()],
resolve: {
alias:
mode === 'profiling'
? { 'react-dom/client': 'react-dom/profiling' }
: {},
},
build: {
// Keep readable names so the Profiler shows components, not "a" and "b".
minify: mode === 'profiling' ? false : 'esbuild',
},
}));Build and preview it with:
npx vite build --mode profiling
npx vite previewOpen the preview URL. The Profiler tab is now active and records real production timings. Other bundlers have an equivalent alias. In Create React App (older projects), npm run build -- --profile does the same job.
Reading minified names
In a plain production build, minification renames functions, so the Components tab may show names like t or n instead of List or Item. Disabling minification in the profiling build, as shown above, avoids this. Source maps can also restore names for source links.
Choosing a build
Common mistakes
- Judging performance from development durations and optimizing code that was never slow.
- Opening the Profiler on a production build and concluding the tool is broken. The tab is simply unavailable.
- Leaving
StrictModedouble renders out of your reasoning, then wondering why logs appear twice in development.
Exercise
Your teammate says a component takes 40 ms to render, based on the Profiler in npm run dev. What should you check before acting on that number, and how would you get a trustworthy one?
Show answer
Development builds inflate durations because of extra checks and, with StrictMode, double rendering. Make a profiling build (a production build with the profiling alias), open it, confirm the extension icon is blue and the Profiler tab works, then record the same interaction and compare. Render counts and render reasons from development are still valid.