Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addon-info doesn't handle React.forwardRef appropriately #4787

Closed
vpicone opened this issue Nov 14, 2018 · 1 comment · Fixed by #4961
Closed

addon-info doesn't handle React.forwardRef appropriately #4787

vpicone opened this issue Nov 14, 2018 · 1 comment · Fixed by #4961

Comments

@vpicone
Copy link
Contributor

vpicone commented Nov 14, 2018

Describe the bug
When forwarding a ref to a child component, the component shows up as <Unknown>. You can set the display name of the wrapper component to the name of the child component, but this means less legible devtools.

To Reproduce
Steps to reproduce the behavior:

  1. Export a component with a React.forwardRef wrapper:
  2. View the story source section of addon-info

Note: If you set the displayName of the wrapper component, addon-info will use that. However, simply using the displayName from the child makes for less readable dev tools, it looks like component nested within itself.

Expected behavior
Story source should ignore the wrapper component <ForwardRef> and display the child before displaying <Unknown>

Code snippets

<Unknown> - currently happening w/o intervention

import React, { forwardRef } from 'react';

const withForwardRef = Component => {
  const forwarder = forwardRef((props, ref) => (
    <Component {...props} innerRef={ref} />
  ));
  return forwarder;
};

export default withForwardRef;

screen shot 2018-11-13 at 1 39 18 pm

<ForwardRef(Component)> - good for dev tools bad for story

import React, { forwardRef } from 'react';

const withForwardRef = Component => {
  const forwarder = forwardRef((props, ref) => (
    <Component {...props} innerRef={ref} />
  ));
  forwarder.displayName = `ForwardRef(${Component.displayName || Component.name})`; // use display name if provided
  return forwarder;
};

export default withForwardRef;

screen shot 2018-11-14 at 10 36 00 am

<Component> (duplicate child) good for story, bad for dev tools

import React, { forwardRef } from 'react';

const withForwardRef = Component => {
  const forwarder = forwardRef((props, ref) => (
    <Component {...props} innerRef={ref} />
  ));
  forwarder.displayName = Component.displayName || Component.name; // use display name if provided
  return forwarder;
};

export default withForwardRef;

screen shot 2018-11-14 at 10 38 06 am

@stale
Copy link

stale bot commented Dec 9, 2018

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants