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

Doc code preview "No display name" #12596

Closed
fcisio opened this issue Sep 28, 2020 · 24 comments
Closed

Doc code preview "No display name" #12596

fcisio opened this issue Sep 28, 2020 · 24 comments

Comments

@fcisio
Copy link

fcisio commented Sep 28, 2020

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

@shilman
Copy link
Member

shilman commented Oct 12, 2020

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

@shilman
Copy link
Member

shilman commented Oct 12, 2020

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

@fcisio
Copy link
Author

fcisio commented Oct 13, 2020

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} />

@andezzat
Copy link
Member

andezzat commented Oct 14, 2020

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..

@fcisio fcisio closed this as completed Oct 15, 2020
@shilman
Copy link
Member

shilman commented Oct 15, 2020

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

@zeckdude
Copy link
Contributor

zeckdude commented Nov 4, 2020

@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.

@gptt916
Copy link

gptt916 commented Nov 7, 2020

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
}

@shilman
Copy link
Member

shilman commented Nov 7, 2020

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

@gptt916
Copy link

gptt916 commented Nov 9, 2020

@shilman It works that way, thank you!

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

@shilman
Copy link
Member

shilman commented Nov 10, 2020

cc @tmeasday @jonniebigodes not sure what to do about this 🤦

@tmeasday
Copy link
Member

Oh man.

@Naxos84
Copy link

Naxos84 commented Dec 14, 2020

I can confirm that {Story()} fixes this issue when using the decorator in Storybook 6.0.27.

I guess that you don't have a solution for that by now?

@aaronnuu
Copy link

When I use the {Story()} solution to fix the <No display name /> issue then all of my hooks within the story stop working (I assume because my story component is now not being called by React.createElement)

@shilman
Copy link
Member

shilman commented Dec 21, 2020

I will try to fix this as part of #12022, and the recommendation will be to use <Story /> for consistency's sake.

@andykenward
Copy link

This is happening on "@storybook/react": "6.3.2" when using a decorator on an individual story.
I am using TypeScript 4.3.4.

// .storybook/main.js

module.exports = {
  stories: ["../src/**/*.stories.@(js|jsx|ts|tsx|mdx)"],
  addons: [
    "@storybook/addon-essentials",
    {
      name: "@storybook/preset-scss",
      options: {
        cssLoaderOptions: {
          modules: {
            localIdentName: CSS_MODULE_STORYBOOK_SCOPE_NAME
          }
        }
      }
    }
  ],
  typescript: {
    reactDocgen: "react-docgen-typescript"
  }
};

This

// component.stories.tsx

 decorators: [
    (Story) => (
      <StoryWrapperDefault>
        <Story />
      </StoryWrapperDefault>
    )
  ]

Output in show code docs.

<StoryWrapperDefault>
  <No Display Name />
</StoryWrapperDefault>

Changing the decorator to the above fix

// Component.stories.tsx

decorators: [(Story) => <StoryWrapperDefault>{Story()}</StoryWrapperDefault>]

Output in show code docs

<StoryWrapperDefault>
  <VoiceSearch
    onClose={() => {}}
    onSubmit={function noRefCheck() {}}
    open
  />
</StoryWrapperDefault>

@shilman
Copy link
Member

shilman commented Jul 2, 2021

@andykenward if you want to get rid of the decorator you can set the excludeDecorators parameter #14652

        docs: {
          source: {
            excludeDecorators: true,
          },
        },
      },

@jonniebigodes we need to rework the doc blocks documentation soon 🙈

@jonniebigodes
Copy link
Contributor

@shilman indeed we do, I'll follow up with you so that we can coordinate how best to document this and move on from there. Sounds good?

@penx
Copy link
Contributor

penx commented Oct 4, 2021

I will try to fix this as part of #12022, and the recommendation will be to use for consistency's sake.

@shilman #12022 is now closed but I still get this issue. It's great that I can use {Story()} but I had to come across this issue before I found the workaround. Something in the docs would be great if you don't think this can be fixed?

@moatorres
Copy link

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

Might be obvious for many, but shilman's comment means (using zeckdude's example above):

Minimal.decorators = [
  Story => (
    <div style={{ margin: '3em' }}>
      {Story()} // instead of <Story />
    </div>
  ),
];

@dechamp
Copy link

dechamp commented Mar 3, 2022

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

Why does this work?

@dechamp
Copy link

dechamp commented Mar 3, 2022

@andykenward if you want to get rid of the decorator you can set the excludeDecorators parameter #14652

        docs: {
          source: {
            excludeDecorators: true,
          },
        },
      },

@jonniebigodes we need to rework the doc blocks documentation soon 🙈

You are so awesome! Thank you! I've be scouring the web for an answer and just found this while i happened to be on the main issue of this thread, thank you!!!!

@jinyoung4478
Copy link

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

Thank you for your help! 😊

WesleyKapow added a commit to zeus-health/ctw-component-library that referenced this issue Nov 15, 2022
This also works around a problem where the component itself would be "No Display Name" -- storybookjs/storybook#12596
@fishkes
Copy link

fishkes commented Jan 4, 2023

@andykenward if you want to get rid of the decorator you can set the excludeDecorators parameter #14652

        docs: {
          source: {
            excludeDecorators: true,
          },
        },
      },

@jonniebigodes we need to rework the doc blocks documentation soon 🙈

Thanks @shilman! for anyone wandering where to add it, you can put it in ./storybook/preview.js

karrui added a commit to opengovsg/design-system that referenced this issue Jan 27, 2023
somehow works to fix "No display name" issue storybook was having when generating source code
See storybookjs/storybook#12596
karrui added a commit to opengovsg/design-system that referenced this issue Jan 27, 2023
…code blocks (#189)

* fix(story): update story for Tiles to show full source code

was too confusing and misleading

* feat: add displayName prop to all forwardRef components

* feat: convert storyFn invocation to function invocation

somehow works to fix "No display name" issue storybook was having when generating source code
See storybookjs/storybook#12596

* feat(storybook): exclude decorators being injected into source code

* feat: add displayName props to subcomponents of main components

* feat(Tile/story): update storybook-only component name for clarity
@bradlocking
Copy link

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

Why does this work?

Can I also get an answer to this?

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

No branches or pull requests