Sub topic 9
Development, production, and profiling builds
This chapter assumes you can run a React app locally, read the Components tab, and have a bundler (Vite or webpack) set up. It covers a point that surprises many people: the same source code can behave differently in DevTools depending on how React was built. Knowing which build you are inspecting stops you from chasing slowdowns that are not real, or from searching for a Profiler that is not there.
Why React ships in more than one build
React is published as several bundles. Your bundler picks one based on process.env.NODE_ENV and on any aliases you configure.
- Development build. Includes warnings, prop and key checks, extra validation, and readable component names. It is larger and noticeably slower.
- Production build. Strips the checks and warnings, and minifies the code. It is what your users should receive.
- Profiling build. A production build of
react-domthat keeps the instrumentation the Profiler needs. It is slightly larger and slower than plain production, but much closer to production than development is.
DevTools works with all three. What it can show differs.
Telling which build a page uses
The React Developer Tools toolbar icon reports the build. Click it on any page that uses React and read the popup text:
- "This page is using the development build of React" means development.
- "This page is using the production build of React" means production, and the Profiler will normally be missing.
- "This page doesn't appear to be using React" means no React was detected. The page may load React late, inside an iframe, or in a form DevTools cannot hook into.
The icon also changes color by state, but the popup text is more reliable than remembering which color means what.
What changes in each tab
The table summarizes what you can expect.
| Behavior | Development | Production | Profiling |
|---|---|---|---|
| Components tab | Full tree, readable names | Works, but names are often minified | Works, names may be minified |
| Profiler tab | Available | Hidden or empty | Available |
| "Why did this render?" | Available | Not available | Available |
| React warnings in Console | Yes | No | No |
| Render timings | Inflated, not representative | Real | Close to real |
| StrictMode double rendering | Yes | No | No |
Components tab in production
The tree still appears, and you can still read props, state, and hooks. The problem is names. A minifier renames ProductListItem to something like a or Ie, so the tree fills with cryptic labels or Anonymous.
If you must debug a production bundle, you have three options:
- Turn off name mangling for function names in your minifier.
- Set
displayNameon important components. - Reproduce the bug in a profiling build with unminified output.
function ProductListItem({ product }) {
return <li>{product.name}</li>;
}
// Survives minification, so the Components tab shows a readable label.
ProductListItem.displayName = 'ProductListItem';Profiler tab
The Profiler depends on instrumentation that plain production builds remove. On a production page you will usually see no Profiler tab, or a message that profiling is not supported. This is deliberate. It is not a bug in your setup.
Why development timings mislead
The Profiler in a development build shows real data, but the numbers are not what users experience. Several costs exist only in development:
- Prop-type and key validation run during render.
- Warnings are computed even when nothing is printed.
- In [StrictMode](https://react.dev/reference/react/StrictMode), React renders components twice to expose impure code and runs effects an extra time on mount. A component that appears to take twice as long may simply be rendered twice.
- Code is unminified and not optimized.
A component that takes 40 ms in development may take 6 ms in production. That means a "slow" component in a development profile might not be worth fixing, and a render that is cheap in development may still matter on a slow phone.
Use development builds to find out why something rendered and how often. That information, such as render counts and render reasons, transfers well between builds. Use profiling builds to decide whether the render time is a problem.
Creating a profiling build
The goal is to run your production bundle, with React's profiling bundle substituted for the normal one. Many frameworks have a switch for this. Next.js has next build --profile, and Create React App has react-scripts build --profile. Check your framework's documentation for the current flag.
With Vite you alias the client entry point yourself. This config enables the profiling build only when you pass --mode profiling, and it leaves minification off so component names stay readable:
// vite.config.js
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig(({ mode }) => {
const profiling = mode === 'profiling';
return {
plugins: [react()],
resolve: {
alias: profiling
? { 'react-dom/client': 'react-dom/profiling' }
: {},
},
build: {
// Keep function and component names readable in the profile.
minify: profiling ? false : 'esbuild',
},
};
});Build and serve it:
npx vite build --mode profiling
npx vite previewWith webpack on React 18, the equivalent is an alias on the react-dom entry points:
// webpack.config.js
module.exports = {
mode: 'production',
resolve: {
alias: {
'react-dom$': 'react-dom/profiling',
'react-dom/client$': 'react-dom/profiling',
},
},
optimization: {
// Readable names in the Components tab and Profiler.
minimize: false,
},
};After the build, open the preview URL. The toolbar popup should say production, and the Profiler tab should now be available. If the Profiler is still missing, the alias was probably not applied. Check that your app imports react-dom/client and not an older path your alias does not cover.
Choosing a build for the task
The following diagram shows how to decide which build to use for a given question.
Common mistakes
Profiling the dev server and trusting the numbers. The development server is the right place to find unnecessary renders. It is the wrong place to decide that a 25 ms commit is a problem.
Shipping the profiling build. The profiling bundle is larger and slower than plain production. Keep it behind a separate build mode or script, and do not deploy it to users.
Expecting render reasons in production. The Profiler setting "Record why each component rendered while profiling" only gives answers in builds that include the instrumentation. In a plain production build, the setting is absent.
Debugging a minified tree. If component names look like t, n, and Ie, you are reading minified output. Switch to an unminified profiling build before spending time on it.
Forgetting StrictMode. If every component seems to render twice during mount in development, check for a <StrictMode> wrapper before you suspect a bug. The behavior disappears in production and profiling builds.
A practical routine
- Find the cause in development. Use the Components tab, highlight updates, and render reasons to find which components render and why.
- Apply the fix, such as
memooruseCallback. - Build in profiling mode and record the same interaction.
- Compare commit times before and after the fix in that build.
- Keep the fix only if the measurement supports it.
This routine keeps cause-finding in the build where DevTools gives the most information, and keeps measurement in the build that resembles reality.
Exercise
A teammate records a Profiler session against your deployed site and reports that the Profiler tab is missing and the Components tab shows names like t and Ie. What does this tell you about the build, and what two changes would let you profile it?
Show answer
The site is a plain production build. The Profiler instrumentation is removed in production, and the minifier renamed the components. To profile it, create a profiling build by aliasing react-dom (or react-dom/client) to react-dom/profiling, or use your framework's profile flag, and disable name minification (or set displayName on key components) so the tree is readable. Serve that build locally and record again.
Exercise
In a development build with StrictMode, a component's mount commit takes 30 ms and it appears to render twice. Is that a reliable measurement of its cost for users? Why or why not?
Show answer
No. The double render is StrictMode's development-only behavior, and development builds also run validation and warnings that production removes. Use the development profile to compare components and count renders, then confirm timing in a profiling build.