-
Notifications
You must be signed in to change notification settings - Fork 47.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
displayName is set to "o" when minifiying Stateless function components via webpack #4915
Comments
React component will use function name as the component's displayName if the displayName is not set. var A = React.createClass({...}) The component's displayName is |
It's problem with minification, not with react. Keep your variables names. |
Uglify may be the culprit, but React is the one that suffers because of it. Not minifying code isn't really a good answer. I tried it with setting |
@jimbolla Why you need uglify in development mode? I suggest you disable uglify in dev mode and enable it in production mode. |
React doesn't do the transformation but feel free to file an issue against babel. If there's something React needs to do differently we can reopen. |
You shouldn't minify in development mode anyway. |
So our code shouldn't rely on |
@silvenon I wouldn't recommend it. Why not compare the type to the object exactly? |
Mind blown 😮 Thanks a bunch! For others who stumble onto this discussion: import React from 'react';
import Foo from './Foo';
const Bar = (props) => {
if (props.children.type === Foo) {
// ...
}
return /* ... */;
}; |
If stateless functions support |
@dminkovsky I haven't tried but I would expect that to already work? |
@spicyj Totally works :D |
@zpao Is that all you can say against this issue (as a person with a badge |
There’s no need to be combative about it. What @zpao is saying is that there is nothing on React side that needs to be fixed because React is not assigning names to your functions. In production, it is expected that you will see minified names. That’s the whole point of minifying. It removes unnecessary code (and mangles identifiers). In development, you should not be using minification in the first place. Minification is causing this, but you shouldn’t minify when you’re just developing. Minification is only needed when you ship a production version of your app to your users. Finally, if you absolutely need those names in minified builds, you can assign them manually: function Foo() {
return <div />;
}
Foo.displayName = 'Foo'; Your bundle size will be larger in this case. There is nothing to be done on the React side here, and it’s not a React issue (or, rather, not an issue at all). I’m locking the discussion because it is taking an unnecessarily emotional tone. Feel free to file a new issue if you believe there is a bug with how React handles this, but please provide more context into why you think it’s a problem, and don’t be negative towards the people trying to help you. |
Given a component defined as:
and minified with webpack's UglifyJsPlugin, you get components with displayName "o" in the React browser tools.
The text was updated successfully, but these errors were encountered: