-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Controls not detecting our component props from propTypes or JSDoc (typescript) types #12292
Comments
Here's a trimmed-down example component and story. // index.js
/**
* @typedef QuantitySelector
*
* @param {Object} props Component props.
* @param {string} props.className CSS class(es).
* @param {number} props.quantity Value to display.
* @param {number} props.minimum Minimum value.
* @param {number} props.maximum Maximum value.
* @param {Function} props.onChange Called when the value changes.
* @param {string} props.itemName The item/value (e.g. product) that the quantity applies to - used for an accessibility message.
* @param {boolean} props.disabled Render the component as disabled and prevent user input.
* @return {*} QuantitySelector component markup.
*/
const QuantitySelector = ( {
className,
quantity = 1,
minimum = 1,
maximum,
onChange = () => null,
itemName = '',
disabled,
} ) => {
// .. component implementation
};
QuantitySelector.propTypes = {
className: PropTypes.string,
quantity: PropTypes.number,
minimum: PropTypes.number,
maximum: PropTypes.number,
onChange: PropTypes.func,
itemName: PropTypes.string,
disabled: PropTypes.bool,
};
export default QuantitySelector; // stories/index.js
import QuantitySelector from '../';
export default {
title: 'WooCommerce Blocks/@base-components/QuantitySelector',
component: QuantitySelector,
};
const Template = ( args ) => <QuantitySelector { ...args } />;
export const Primary = Template.bind( {} );
// Primary.args = {
// disabled: false,
// quantity: 1,
// itemName: 'widgets',
// }; |
Update – I've pasted in a 100% TypeScript Code here: woocommerce/woocommerce-blocks@2a35668 🎉 screenshot of args working: (!) This is using the same webpack and other config, so I think the problem is with our JavaScript components, and how we can export the PropTypes & descriptions so Is there a way to use Or any ideas for where our proptypes might be getting lost. Just confirming - |
@haszari we use args with PropTypes all the time and there are numerous examples in the monorepo and probably in the Storybook design system. It's definitely an issue with your custom webpack config. |
Highly likely! I'll keep digging, I'm guessing there's some interaction with other plugins/steps in the webpack config (babel, react). I can try disabling various plugins and ensure everything's up to date. 🤞 |
I'm not sure if im having the same issue as you, but it sounds the same. My ___docgenInfo is populated and I just tried the following which works...
I thought it was a webpack issue but I don't think so now |
@imeredith different issue. happy to help diagnose if you open a new issue with a bit more info to help see what's going on. |
I'm also running into this issue and I can confirm the following:
Given both of those statements it's not clear to me what the actual issue is here, only that
I could assist by debugging in my local env if I could get some direction on where to start checking around. Edit: this is "either" the babel config, or it's some sort of package conflict. I literally removed all my packages locally, swapped them in with the packages from this other repo (like 1/4th of the packages), removed my local babel.config.js file, and removed my yarn.lock and reinstalled, and that got things to start generating. Going to do more research. |
@reywright if you have a simple repro, i'd love to take a look at it. |
It's 100% the babel config file for me, FYI. Nuking that file makes everything work fine. Edit: I'm not really sure how I'd go about recreating this "simply". I think the easiest option here would be to see an example of a babelrc file that mirrors how you're configuring it in the webpack settings. Either that, or allow an option to disable the loading of the babel file. One other thought here: it might be helpful to include some instructions on how to merely "alter" the babel configuration in webpack. One of the dangers of this setup right now, is if someone wants to have their own custom babel config, it could diverge from storybook specific. |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
I might have a similar problem. After spending a full day researching and trying different things, nothing works and the automatic args table is not showing my components proptypes definitions. I was mainly following these instructions: https://storybook.js.org/docs/ember/writing-docs/doc-blocks I've put the whole code online (based on my client's complex Stroybook config), with just a little bit of cleanup, and left only one story https://github.com/yairEO/sb-args-table-not-showing Files of interest:
Thanks to whoever shed light onto this mystery |
I faced the same issue when I added a custom babel configuration in my application. After some debugging I realized storybook could not fetch the components' proptypes because of this evaluation:
That means How did I solve it? Add these dependencies in your project
Add the following addon in your storybook's main.js
Add this plugin in your .babelrc
Now I haven't completely understood why storybook drops react-docgen when using a custom babel configuration file. I hope to have shed some light ;) |
Gadzooks!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.4.0-alpha.33 containing PR #15928 that references this issue. Upgrade today to the
Closing this issue. Please re-open if you think there's still more to do. |
Previously our Babel configuration conflicted with the one provided by default by Storybook, making us unable to leverage the automatic detection of properties from both JS and TS components to create controls (formerly known as knobs). Upgrading to 6.4.0 fixes a bug that makes it easier to work with Babel configurations. Also done here: * Removed a few deprecated addons in favor of the replacement ones bundled within Storybook Essentials. * Add auto-detection of certain control types depending on the property names * Add support for TS stories More context: storybookjs/storybook#12292
Previously our Babel configuration conflicted with the one provided by default by Storybook, making us unable to leverage the automatic detection of properties from both JS and TS components to create controls (formerly known as knobs). Upgrading to 6.4.0 fixes a bug that makes it easier to work with Babel configurations. Also done here: * Removed a few deprecated addons in favor of the replacement ones bundled within Storybook Essentials. * Add auto-detection of certain control types depending on the property names * Add support for TS stories More context: storybookjs/storybook#12292
…) (#5264) * Migrate Storybook to 6.4.0 and enable auto-detection of controls (#5249) Previously our Babel configuration conflicted with the one provided by default by Storybook, making us unable to leverage the automatic detection of properties from both JS and TS components to create controls (formerly known as knobs). Upgrading to 6.4.0 fixes a bug that makes it easier to work with Babel configurations. Also done here: * Removed a few deprecated addons in favor of the replacement ones bundled within Storybook Essentials. * Add auto-detection of certain control types depending on the property names * Add support for TS stories More context: storybookjs/storybook#12292 * Use `react-docgen` only in development environments This should reduce production bundle size dramatically. The only problem here is that Storybook runs its `build` command with the `NODE_ENV` set to `production`. For this reason, we change the script to provide `BABEL_ENV` set to `development` to still make sure the correct configuration is loaded, while trying to reduce any side-effects on changing the whole `NODE_ENV`.
…commerce#5249) (woocommerce#5264) * Migrate Storybook to 6.4.0 and enable auto-detection of controls (woocommerce#5249) Previously our Babel configuration conflicted with the one provided by default by Storybook, making us unable to leverage the automatic detection of properties from both JS and TS components to create controls (formerly known as knobs). Upgrading to 6.4.0 fixes a bug that makes it easier to work with Babel configurations. Also done here: * Removed a few deprecated addons in favor of the replacement ones bundled within Storybook Essentials. * Add auto-detection of certain control types depending on the property names * Add support for TS stories More context: storybookjs/storybook#12292 * Use `react-docgen` only in development environments This should reduce production bundle size dramatically. The only problem here is that Storybook runs its `build` command with the `NODE_ENV` set to `production`. For this reason, we change the script to provide `BABEL_ENV` set to `development` to still make sure the correct configuration is loaded, while trying to reduce any side-effects on changing the whole `NODE_ENV`.
…commerce#5249) (woocommerce#5264) * Migrate Storybook to 6.4.0 and enable auto-detection of controls (woocommerce#5249) Previously our Babel configuration conflicted with the one provided by default by Storybook, making us unable to leverage the automatic detection of properties from both JS and TS components to create controls (formerly known as knobs). Upgrading to 6.4.0 fixes a bug that makes it easier to work with Babel configurations. Also done here: * Removed a few deprecated addons in favor of the replacement ones bundled within Storybook Essentials. * Add auto-detection of certain control types depending on the property names * Add support for TS stories More context: storybookjs/storybook#12292 * Use `react-docgen` only in development environments This should reduce production bundle size dramatically. The only problem here is that Storybook runs its `build` command with the `NODE_ENV` set to `production`. For this reason, we change the script to provide `BABEL_ENV` set to `development` to still make sure the correct configuration is loaded, while trying to reduce any side-effects on changing the whole `NODE_ENV`.
Describe the bug
Hi there, sorry for the vague bug!
We've recently upgrade to Storybook 6.0 and we're keen to migrate our stories from
Knobs
toControls
addon, and the other cool stuff in essentials based on theargs
pattern, e.g. automatic docs.Our project uses React, so we're using Storybook-react. The project is WooCommerce Blocks, and there's an open PR dedicated to this: woocommerce/woocommerce-blocks#3046
Our components include PropTypes declarations. Example component: https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/51137ecb81da55c98cfc7bc5ed3dcd4e2aa75a8b/assets/js/base/components/quantity-selector/index.js
Note - we're planning on migrating to JSDoc typescript declarations (in our JS files - we're not using TypeScript lang). So if this is supported by Storybook we can switch to that. So far I can't get either option to work - the controls don't show up in Storybook unless I manually specify them via story.args prop.
Our project is quite complex and we have a custom webpack config. In the related branch / PR the webpack config is overridden using
webpackFinal
config prop.With
--debug-webpack
I've confirmed that the react-docgen plugin is in the config:How can I debug where it's going wrong, or ensure it has access to our prop declarations?
To Reproduce
Sorry – I don't have a minimal reproduce repo.
Expected behavior
Hoping to get this working, again apologies for the open-ended bug report.
Ideally we can nail down the flow of data into react-docgen and document exactly what's expected here, and how to diagnose problems.
System:
Please paste the results of
npx sb@next info
here.Additional context
The text was updated successfully, but these errors were encountered: