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.

React component names mangling

See original GitHub issue

Is this a bug report?

Yes. We aren’t able to make automation testing.

Did you try recovering your dependencies?

Yes

Environment

  1. node -v: 9.4.0
  2. npm -v: 5.6.0
  3. yarn --version (if you use Yarn): 1.3.2
  4. npm ls react-scripts (if you haven’t ejected): react-scripts-ts@2.13.0

Then, specify:

  1. Operating system: Windows 10
  2. Browser and version (if relevant):

Steps to Reproduce

  1. create-react-app
  2. yarn build
  3. Open in browser → React DevTools

Expected Behavior

We would like to see unminified component’s class names for our staging environment to make end-to-end automated testing. We use these names in our test cases, so we don’t want to see them mangled.

Actual Behavior

Class names are mangled.

image

It’s easy to fix by adding options to disable mangling in webpack.config.prod.js:

new webpack.optimize.UglifyJsPlugin({
	// ...
	mangle: {
		keep_classnames: true,
		keep_fnames: true
	},
	// ...
}),

Maybe adding the option to .env file is good way here?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
gaearoncommented, Oct 4, 2018

One thing you can do is to explicitly give some components displayName. Minifier won’t remove it.

function Stuff() {}
Stuff.displayName = 'Stuff'

Giving it to every component is overkill and will bloat your bundle. But if you strategically pick a few dozen components (depending on your product size) I think it will give you a good balance.

3reactions
Timercommented, Mar 26, 2018

No, sorry. Giving these sort of configuration options are outside of our values. If you feel strongly about this, you’ll need to eject.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Obscurify react code in production by automatically changing ...
UglifyJS has options to mangle (obscurify) names: ... (I think React is more interested in the smaller JS files than obscuring code.).
Read more >
Reduce minified code size by property mangling | Tan Li Hau
This behavior of renaming variable name to compress JavaScript code is called Mangle.
Read more >
Name mangling in Python - GeeksforGeeks
Accessing Name Mangled variables​​ The name mangling process helps to access the class variables from outside the class. The class variables can ...
Read more >
Optimizing Performance - React
When a component's props or state change, React decides whether an actual DOM update is necessary by comparing the newly returned element with...
Read more >
Use Illegal Identifier Names | ReScript Language Manual
The Reason compiler will remove the leading underscore when outputting JavaScript (so the JavaScript will have <Component type="POST" /> ). The removal of...
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