storybook: Prop table broken in 5.3.2 with propTypes
Describe the bug
On upgrading to 5.3.2, any props defined with propTypes are not building the prop table
To Reproduce Declare propTypes for a component. Open storybook and see that it hasn’t generated a prop table.
Expected behavior Expected to see prop information
Screenshots
Before

After upgrading

Code snippets
class Dropdown extends React.Component {
constructor() {
super()
this.state = { show_action_sheet: false }
this.toggleActionSheet = this.toggleActionSheet.bind(this)
}
toggleActionSheet() {
this.setState({ show_action_sheet: !this.state.show_action_sheet })
}
render() {
const {
split,
} = this.props
const isMobile = detectMobile()
let DropdownComponent
if (split) {
DropdownComponent = isMobile ? SplitDropdownActionSheet : SplitDropdownRegular
} else {
DropdownComponent = isMobile ? DropdownActionSheet : DropdownRegular
}
return (
<DropdownComponent {...this.props}
show_action_sheet={this.state.show_action_sheet}
toggleActionSheet={this.toggleActionSheet}
/>
)
}
}
Dropdown.propTypes = {
split: PropTypes.bool, // pass true for a split button. If true, must pass either href or onClick
href: PropTypes.string, // href for split button
onClick: PropTypes.func, // onClick handler for split button
noCaret: PropTypes.bool, // pass true to not show a caret
action_sheet_title: PropTypes.oneOfType([ // pass this to show a title displayed for context on action sheet
PropTypes.string,
PropTypes.element,
]),
className: PropTypes.string,
jane_only: PropTypes.bool,
pullRight: PropTypes.bool,
disabled: PropTypes.bool,
options: PropTypes.arrayOf(PropTypes.object).isRequired, // [{}, {}]
bsSize: PropTypes.oneOf(
['large', 'lg', 'small', 'sm', 'xsmall', 'xs']
),
bsStyle: PropTypes.oneOf(
["success", "warning", "danger", "info", "default", "primary", "link"]
),
}
System:
System:
OS: macOS Mojave 10.14.6
CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
Binaries:
Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
Yarn: 1.19.2 - /usr/local/bin/yarn
npm: 6.12.1 - ~/.nvm/versions/node/v8.11.3/bin/npm
Browsers:
Chrome: 79.0.3945.117
Safari: 13.0.4
npmPackages:
@storybook/addon-actions: ^5.3.2 => 5.2.5
@storybook/addon-docs: ^5.3.2 => 5.2.5
@storybook/addon-knobs: ^5.3.2 => 5.2.5
@storybook/addon-links: ^5.3.2 => 5.2.5
@storybook/addons: ^5.3.2 => 5.2.5
@storybook/react: ^5.3.2 => 5.2.5
Additional context Add any other context about the problem here.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 38 (16 by maintainers)
Thanks for the helpful explanation @shilman, it explained why it was working before and I realized that we actually hadn’t previously added that as a dependency as it had worked without it.
@danilovaz I fixed by adding
babel-plugin-react-docgenas a dev dependency, and then addingreact-docgento plugins for thebabel-loaderin my webpack config (as our project doesn’t use a .babelrc).Its’a an option @shilman , I dont like it though.
It shouldn’t have ever work without the proper babel plugin setup and it’s an easy fix for the user.
If we had back the fallback, I fear we might end up with weird issues that might take a lot of our time to figure out what’s happening.
Could we instead update the error message to suggest to configure properly the babel plugin required by the props table?
@artemAp yes, if it’s even possible. A lot of the information we need might already be stripped out of the published package. At any rate, we’re still stabilizing the current props table for now
@shilman Will you plan to support props from installed package in future?
@patricklafrance THanks, Patrick, unfortunately this didn’t work.
I write components in ES (before webpack/babel) and stories in js (not mdx)
=>
yarn storybook --debug-webpackgives me the following, which is, I suspect, the default storybook babel configuration, that executes added to my user settings defined inbabel.config.jsin the root of/myproject.As you can see, the docgen plugin is actually loaded. I have tried, without much understanding, to copy my
babel.config.jsto the.storybookfolder, without any result either.My presets file
./.storybook/presets.js'is as followsmodule.exports = ['@storybook/addon-docs/preset'];Also I noticed
console.log(Component.__docgenInfo)yields nothingMy components are all generated with this template (inside a yeoman generator): https://github.com/fwrlines/generator-react-component/blob/master/generators/app/templates/Component.js
My stories look all like this (also generated with yeoman) : https://github.com/fwrlines/generator-storybook-story/blob/master/generators/app/templates/story.js
I have tried with Class Components as well.
In 5.2.8 this was half working : the propotypes table and defaults were detected and appeared in storybook docs, but the description of each prop didn’t show at all. Now I only have a “No props found for this component” message for every component.
Edit
Edit 2 : fixed it, unknowingly
npx -p @storybook/cli sb init --type react, installednpm i -D prop-typesand used the same yeoman generators for stories/components than before. Docgen works finebabel.config.jsto the root of the new bootstrapped project. Installed the babel plugins through npm. I was wondering whether this would mess up the working config but no, docgens still works fine..storybookfolder)Edit 3 : found the source of the bug
I was doing this :
Instead of
In files where components are defined
For a weird reason, Storybook 5.3 voids the contents of the docgen when using the first option, independently of where the dynamic import is in the file