question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make it easier to properly profile with the React DevTools.

See original GitHub issue

I wrote a blog post about how to properly profile a React App for Performance and I use a react-scripts app to demonstrate how to do it. There are a few steps in there that I’d love to make easier.

Specifically, you have to go into ./node_modules/react-scripts/config/webpack.config.js to update the webpack config to add this to resolve.alias:

'react-dom$': 'react-dom/profiling',
'scheduler/tracing': 'scheduler/tracing-profiling',

And you have to add this to the Terser options:

keep_classnames: true,
keep_fnames: true,

It’s a bit of an annoying process and I think we could make it a lot easier (and hopefully encourage people to profile their apps in the process).

Describe the solution you’d like

We’d make a change here: https://github.com/facebook/create-react-app/blob/0d1775e739b091affaf8b11a85aaa435fc53ee64/packages/react-scripts/config/webpack.config.js#L302-L306

-      alias: {
+      alias: removeEmpty({
         // Support React Native Web
         // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
         'react-native': 'react-native-web',
+        'react-dom$': isEnvProductionProfile ? 'react-dom/profiling' : null,
+        'scheduler/tracing': isEnvProductionProfile ? 'scheduler/tracing-profiling' : null,
+      }),
-      },

Where removeEmpty is something like (borrowed from webpack-config-utils):

function removeEmpty(input) {
  const output = {}
  Object.keys(input).forEach(key => {
    const value = input[key]
    if (typeof value !== 'undefined') {
      output[key] = value
    }
  })
  return output
}

and isEnvProductionProfile is defined as: isEnvProduction && Boolean(process.env.PROFILE_APP).

We’d also add this right above: https://github.com/facebook/create-react-app/blob/0d1775e739b091affaf8b11a85aaa435fc53ee64/packages/react-scripts/config/webpack.config.js#L237

keep_classnames: isEnvProductionProfile,
keep_fnames: isEnvProductionProfile,

Describe alternatives you’ve considered

Currently the alternative is to change it manually (and if you deploy from your local build then you need to remember to remove your edits).

Additional context

I’m bringing this up because I’d love to update my blog post to simply be: “Now, run the build in profiling mode with npx cross-env PROFILE_APP=true npm run build.” That would be awesome. And it would make every-day profiling much simpler as well.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:20
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
kentcdoddscommented, Sep 25, 2019

I think so!

3reactions
kentcdoddscommented, Oct 3, 2019

Huzzah!!! Thanks @iansu! And well done @JacobMGEvans 👏

I understand that my needs are not your deadlines, but if this could be released for my workshop by next Monday that would be awesome 😁

Read more comments on GitHub >

github_iconTop Results From Across the Web

Profile a React App for Performance - Kent C. Dodds
Open the browser developer tools by right clicking anywhere on the page and clicking "Inspect." Then select the "⚛ Profiler" tab. This is...
Read more >
The definitive guide to profiling React applications
Knowing how to profile a React application to improve real-world performance is a good tool in any front-end developer's toolkit.
Read more >
Optimizing Performance - React
Optimizing Performance · Use the Production Build · Profiling Components with the DevTools Profiler · Virtualize Long Lists · Avoid Reconciliation.
Read more >
Profiling Performance of React Apps using React Profiler
Like I said, profiling a React application is very easy. Now let's see how we can read the performance data we obtained.
Read more >
Profiling Performance with React Developer Tools | Pluralsight
The first thing to do is install the developer tools. How you do this depends on the browser you are using to run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found