storybook: [Bug]: Using typescript: "react-docgen-typescript" breaks source preview

Describe the bug

Using the following in my main config breaks the preview source code.

  typescript: {
    reactDocgen: 'react-docgen-typescript',
  },

Screenshot 2024-03-15 at 09 53 15 Screenshot 2024-03-15 at 09 53 07

To Reproduce

https://stackblitz.com/edit/github-cuvfy3?file=.storybook%2Fmain.ts

System

My local system info


Storybook Environment Info:

  System:
    OS: macOS 14.4
    CPU: (10) arm64 Apple M1 Pro
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
    pnpm: 8.15.4 - ~/.nvm/versions/node/v20.11.1/bin/pnpm <----- active
  Browsers:
    Chrome: 122.0.6261.129
    Safari: 17.4
  npmPackages:
    @storybook/addon-a11y: 8.0.0 => 8.0.0
    @storybook/addon-docs: 8.0.0 => 8.0.0
    @storybook/addon-essentials: 8.0.0 => 8.0.0
    @storybook/addon-interactions: 8.0.0 => 8.0.0
    @storybook/addon-mdx-gfm: 8.0.0 => 8.0.0
    @storybook/addon-themes: 8.0.0 => 8.0.0
    @storybook/addon-viewport: 8.0.0 => 8.0.0
    @storybook/blocks: 8.0.0 => 8.0.0
    @storybook/core-server: 8.0.0 => 8.0.0
    @storybook/manager-api: 8.0.0 => 8.0.0
    @storybook/preview-api: 8.0.0 => 8.0.0
    @storybook/react: 8.0.0 => 8.0.0
    @storybook/react-vite: 8.0.0 => 8.0.0
    @storybook/react-webpack5: 8.0.0 => 8.0.0
    @storybook/testing-library: 0.2.2 => 0.2.2
    @storybook/theming: 8.0.0 => 8.0.0
    @storybook/types: 8.0.0 => 8.0.0
    chromatic: 11.0.8 => 11.0.8
    eslint-plugin-storybook: 0.8.0 => 0.8.0
    storybook: 8.0.0 => 8.0.0
    storybook-mock-date-decorator: 1.0.1 => 1.0.1


### Additional context

_No response_

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 8
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Hey everyone! This issue is solved in #26566 and will be released soon. Thanks for your patience 🙏

Hey thanks for the reply. So I just figured out that using the LinkTo from the @storybook/addon-links/react in an arg (which allows me to link between stories using the Storybook router) causes this issue. This confused me because any other JSX/ComponentType props (with or without args) would display a set object button.

Honestly, I am having a lot of issues in general with the autodocs. I would normally be happy to take the time to file bugs and even do a repro, but I’ve spent so much time on it that I’ve had to switch gears. To be fair I don’t doubt it’s tough on your end when you don’t have control of the main dependency (react-docgen).

With how things are right now in this project, I’ll either have to either have an argType for most/all args with various overrides or it might just be easier to create mdx pages with manual prop tables. But I’m still very appreciative about Storybook in general. Thanks for all you do!

Edit: the issue wasn’t just with LinkTo, it does seem to be consistent when using JSX/React Elements as args. However as an aside, I am sometimes getting this when providing the arg as a component instead (these props are designed to take either React.ReactNode or ComponentType:

image

After poking at this just a little more, I now see that I get something different in the control cell when an arg is provided, vs. a default value… even when the arg is the same type as the default value.

Example with a default value but no arg:

image

Same prop but this time with an arg loader: () => <div>Loading...</div>:

image

Sorry again for adding all this to a closed issue, but I original thought the fix to this one might have changed behavior (turns out that I changes some args around the same time…). All in all it sounds like maybe we have different expectations for what the UX should be, or at least what is worth doing given the challenge. IMO, if a proper control that looks good and makes sense to the user can’t be displayed then nothing (or some message stating such) should be displayed.

Pretty much narrowed it down to the 8.0.0-rc.4 package of @storybook/react. If you downgrade it to rc3 for that package, clear all caches (browser + delete node_modules and run nx reset if using nx, etc) and then npm install it works again.

Maybe this PR: https://github.com/storybookjs/storybook/pull/26382 ?

EDIT: be sure to pin it to 8.0.0-rc.3 (no ^)

@adrianaferrugento looks like this issue can be mitigated by using react-docgen instead, right?

It can, but for me I lose a lot of type details when usingreact-docgen E.g. react-docgen image react-docgen-typescript image (this is a Font Awesome SizeProp, just used as an example)

So now I have to choose between better types in the controls, or nice code in the examples, which is a bit of a bummer.