-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Feature request: Allow to disable displayName wrapping globally #559
Comments
So we will have a lot of comonents with same names, as every HOC is a component itself. |
Maybe the react devtools could handle HOCs in a special manner. Devs could maybe set a static property or something to let devtools know it is a HOC. What I’m saying is maybe this is a concern for our tooling and not so much for this library. |
@istarkov @timkindberg const wrapDisplayName = (BaseComponent, hocName) => {
if (process.env.RECOMPOSE_SAME_DISPLAY_NAME) {
return BaseComponent
}
return `${hocName}(${getDisplayName(BaseComponent)})`
} We need this for react virtual dom serializers (jest snapshots e.g., enzyme). In our tests and storybook we have |
Isnt it will cause a lot of same displayNames? When every hoc have the same name as a base? (code above looks strange :-) not sure what you want to return inside if |
Also I wanna say I highly dislike current displayName approach so open to any proposals |
it will. So use case. We have const enhance = compose(
withState('value', 'onChange', props => props.value),
withHandlers({
onChange: props => value => {
action('change')(value);
props.onChange(value);
},
onFocus: () => action('focus'),
onBlur: () => action('blur'),
onLabelClick: () => action('labelClick'),
onCut: () => action('cut'),
onCopy: () => action('copy'),
onPaste: () => action('paste'),
})
) Than compose our component and show in storybook. |
original displayName upd: |
Could we somehow allow users to redefine wrapDisplayName for example using React Context without a big perf affect at dev and possibly prod mode? ( We can always add something like registerWrapDisplayName which will change the default behaviour but I dont like the idea of changing global exports) so any ideas? |
I'm seeing issues in our Jest Snapshot testing that seem related to this. In our production build pipeline we run tests with
and:
I'm guessing it has something to do with this issue... more specifically: recompose/src/packages/recompose/getContext.js Lines 15 to 19 in c830f18
And this, etc: recompose/src/packages/recompose/withProps.js Lines 10 to 15 in e50934e
If anyone can confirm that this behavior is expected I'd appreciate it. Otherwise, just posting here for anyone else who comes across it. I forked this repo and will see if I can confirm as well. In my opinion it doesn't seems ideal for components to have different names by environment. I imagine it would be an issue affecting anyone using If this is in fact the expected behavior, perhaps we should add a way of opting out with either an option or |
Also, perhaps my above comment justifies a separate issue (support for snapshot tests). Please let me know and I can open one. |
@istarkov I encountered the same problem with long display names at work. We have our own HOCs and we are flattening the display name to the most relevant one. |
I widely use Recompose at all projects I do. And it's not useful to see displayNames like
pure(withHandlers(withProps(withPropsOnChange(ComponentName))))
at React dev tools and I would like to see justComponentName
instead because wrapped names don't make sense for me (and I guess for 99% developers) at all. I would like to disable name wrapping globally. Is that something you'd implement?Thank you for the great library!
The text was updated successfully, but these errors were encountered: