storybook: [Bug]: V7, controls description not showing, TypeScript, Vite, react-docgen-typescript
Describe the bug
Every component in Storybook has TypeScript types where every prop has JSDoc comment.
Previously in Storybook 6 everything worked correctly.
All controls had description and default values shown and they were populated correctly via react-docgen-typescript
.
But after migrating to Storybook 7 and going “full Vite” controls are not showing any description.
I also tried Webpack5 with Storybook 7 and seems that description did show up:
I’ve also switched between react-docgen
and react-docgen-typescript
and react-docgen
did work better, but still some comments/description were missing.
To Reproduce
The project is private, don’t have rights to share it.
System
System:
OS: macOS 13.2.1
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Binaries:
Node: 16.19.1 - ~/.nvm/versions/node/v16.19.1/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v16.19.1/bin/yarn
npm: 8.19.3 - ~/.nvm/versions/node/v16.19.1/bin/npm
Browsers:
Chrome: 114.0.5735.133
Safari: 16.3
npmPackages:
@storybook/addon-a11y: ^7.1.0-alpha.32 => 7.1.0-alpha.33
@storybook/addon-actions: ^7.1.0-alpha.32 => 7.1.0-alpha.33
@storybook/addon-docs: ^7.1.0-alpha.32 => 7.1.0-alpha.33
@storybook/addon-essentials: ^7.1.0-alpha.32 => 7.1.0-alpha.33
@storybook/addon-links: ^7.1.0-alpha.32 => 7.1.0-alpha.33
@storybook/blocks: ^7.1.0-alpha.32 => 7.1.0-alpha.33
@storybook/client-api: ^7.1.0-alpha.32 => 7.1.0-alpha.33
@storybook/react: ^7.1.0-alpha.32 => 7.1.0-alpha.33
@storybook/react-vite: ^7.1.0-alpha.32 => 7.1.0-alpha.33
Additional context
I have a monorepo setup and Storybook collects all the story files correctly. These are the settings:
// apps/workshop/.storybook/main.ts
import type { StorybookConfig } from '@storybook/react-vite';
import remarkGfm from 'remark-gfm';
const conf: StorybookConfig = {
stories: [
'../src/*.mdx',
'../src/hooks/*.mdx',
'../../../packages/**/*.stories.@(js|jsx|ts|tsx|mdx)'
],
staticDirs: ['./static'],
framework: {
name: '@storybook/react-vite',
options: {}
},
addons: [
{
name: '@storybook/addon-essentials',
options: {
docs: true,
actions: true,
backgrounds: true,
controls: true
}
},
{
name: '@storybook/addon-docs',
options: {
transcludeMarkdown: true,
mdxPluginOptions: {
mdxCompileOptions: {
// Styled tables, etc.
remarkPlugins: [remarkGfm]
}
}
}
},
'@storybook/addon-a11y',
'storybook-addon-designs'
],
typescript: {
check: true,
// react-docgen-typescript not working atm
reactDocgen: 'react-docgen-typescript',
reactDocgenTypescriptOptions: {
shouldExtractLiteralValuesFromEnum: true,
shouldRemoveUndefinedFromOptional: true,
propFilter: (prop) =>
prop.parent ? !/node_modules/.test(prop.parent.fileName) : true
}
},
docs: {
autodocs: true
}
};
export default conf;
// apps/workshop/vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), tsconfigPaths()],
resolve: {
alias: [
{
// https://github.com/vitejs/vite/issues/5764
// this is required for the SCSS modules
find: /^~(.*)$/,
replacement: '$1'
}
]
}
});
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 5
- Comments: 15 (2 by maintainers)
This same happened in my monorepo. It also happened in clean React + Vite + Storybook setup project. If you have following in your Storybook config then properties are not getting picked up. Using displayName or forwardRef made no difference.
Also if
compilerOptions
is just empty{}
then it also doesn’t work. Removing compilerOptions field fixes everything. This issue was not present in Storybook 6. This is problematic becausereact-docgen-typescript
specifically recommends to set those options for better speed but currently that completely breaks everything.I had the same issue, where the argsTypes are not properly inferred. I have storybook running in a independent package inside a mono-repository. So the solution has been adding the following to my
main.ts
configuration.@Yangseungchan, not resolved yet. I get some better result with
react-docgen
instead of areact-docgen-typescript
, but it still missing out a lot of comments and some types can’t be resolve at all. I found another thread that has similar discussion, but looks like this is a common issue with the monorepos at the moment.In the latest version ^8.0.8, the forwardRef situation still exists, and it cannot automatically create automatic documents for me.
I use storybook in Nextjs.
This is my component:
@Kureyko hey I just had a similar issue and somehow managed to find a workaround.
Do any of your components (
ImageBanner
,ImageBanner.Content
, orImageBanner.Image
) happen to assign itsdisplayName
after their declarations? For example, likeImageBanner.displayName = 'ImageBanner'
. In my case I was usingReact.forwardRef
and I was passing the component to be wrapped as an anonymous function, which triggered react/display-name eslint rule, so I just slappedMyComponent.displayName = 'MyComponent'
after the declaration to suppress the red squiggly lines… which was, to my surprise, interfering with the docgen process (I usereact-docgen-typescript
). So after commenting outMyComponent.displayName = 'MyComponent'
, the docgen worked as expected again.Here are some reproducible code snippets:
For core maintainers
@shilman Hey guys, this issue seems to be caused by
generateDocgenCodeBlock()
invite-plugin-react-docgen-typescript
. Specifically, it seems like whendisplayName
prop of a React component is assigned manually (like in the example above),generateDocgenCodeBlock()
produces code that attaches__docgenInfo
to the wrong component (e.g., producesSubComponent1.__docgenInfo = {...}
instead ofMyComponent.__docgenInfo = {...}
).I’ll share the generated code below:
No manual
displayName
assignment (see thetry
block at the end)Manual
displayName
assignment (see thetry
block at the end)@shilman However, even in version 8.0 react-docgen, we are having a lot of difficulty migrating using react-docgen due to the following issue. This issue is a fatal drawback for developers who customize UI libraries or frequently use forwardRef. Still, I can feel that performance has become faster after migrating to react-docgen, so I hope that this issue is resolved as soon as possible.
@siosio34 We have improved
react-docgen
and are recommending that as the default in 8.0. As forreact-docgen-typescript
the “help wanted” label means that we’d be happy to accept fixes from the community from this issue but have not prioritized it for the core team.Using NX monorepo, React lib with Storybook v7.5.3 and Vite to build it. This worked for me:
in
main.ts
file and within each component I got rid ofComponent.displayName = 'Component'
line and exposed both named and default export of Component from the same file.Same issue here, don’t have any of the forwardRef stuff above. Description / controls not auto populated from my comments in the component.