Storybook: Doc code preview "No display name"

Created on 28 Sep 2020  路  11Comments  路  Source: storybookjs/storybook

Describe the bug
The Doc code preview does not display the component name correctly.

To Reproduce

  1. Create a component with emotion js "Styled"
  2. Create a component with "Theme UI"
  3. Use those components in stories
  4. Check the doc code preview

Expected behavior
The component name should display normally

Screenshots
Shot_0
Shot_0 1

Code snippets
Shot_0 2

P1 docs source bug compatibility with other tools has workaround

Most helpful comment

What happens if you use {Story()} instead of <Story />?

All 11 comments

@fcisio Is this still broken in the latest alpha? We made some improvements in #12638

@andezzat any chance you can take a look at this as follow-on to your "exotic components" fix? 馃檹

Hi @shilman
The [object Object] seems to be fixed. But still having issues with "No Display Name".

I found a quick fix for now:

Burger.displayName = "Burger"
const Template = (args) => <Burger {...args} />

The [object Object] seems to be fixed. But still having issues with "No Display Name".

It sounds like styled(MyComp) doesn't assign displayName. I'm not sure if that's an SB issue then..

@andezzat is there any way we can detect that it's a styled component and automatically extract the display name from the wrapped component?

@shilman I'm experiencing a similar issue, but only when I use a decorator.

Without a decorator, the code preview shows me this:

<Tooltip title="Hi there!">
  <Button size="small">
    Open based on hover
  </Button>
</Tooltip>

With the decorator, I get this:

<div
  style={{
    margin: '3em'
  }}
>
  <No Display Name />
</div>

Here's my full story:

export const Minimal = args => {
  return (
    <Tooltip title="Hi there!" placement="top" {...args}>
      <Button type="primary" size="small">
        Open based on hover
      </Button>
    </Tooltip>
  );
};
Minimal.decorators = [
  Story => (
    <div style={{ margin: '3em' }}>
      <Story />
    </div>
  ),
];

I doubt it's an issue with the Tooltip component, since the code preview works fine without the decorator. Please let me know if you think this is related or if I should create a new issue.

Exact same issue as @zeckdude described, issue only shows when I'm using a decorator.

My story looks like this:

export default {
  title: 'CheckboxTree',
  component: CheckboxTree,
  decorators: [
    withKnobs,
    (Story) => <div style={{ maxWidth: '256px' }}><Story/></div>
  ],
};

export const Valid = (args) => <CheckboxTree {...args} />

Valid.args = {
  nodes: validData
}

What happens if you use {Story()} instead of <Story />?

@shilman It works that way, thank you!

Perhaps the documentation needs to be updated here: https://storybook.js.org/docs/react/writing-stories/decorators

cc @tmeasday @jonniebigodes not sure what to do about this 馃う

Oh man.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

levithomason picture levithomason  路  3Comments

arunoda picture arunoda  路  3Comments

miljan-aleksic picture miljan-aleksic  路  3Comments

MrOrz picture MrOrz  路  3Comments

tirli picture tirli  路  3Comments