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

addon-info: prop descriptions are empty with CRA #5777

Closed
sealightPT opened this issue Feb 26, 2019 · 11 comments
Closed

addon-info: prop descriptions are empty with CRA #5777

sealightPT opened this issue Feb 26, 2019 · 11 comments
Labels
addon: info cra Prioritize create-react-app compatibility has workaround inactive
Milestone

Comments

@sealightPT
Copy link

sealightPT commented Feb 26, 2019

The prop descriptions don't show for my React App components.
The App was created with CRA and it's not ejected.

image

Example:

/** Displays a country flag */
class Flag extends React.Component {
    render() {
        return <img (...) />
    }
}
Flag.propTypes = {
    /** Flag country code */
    code: PropTypes.string.isRequired,
    /** Alternative text */
    alt: PropTypes.string,
    /** Width size */
    width: PropTypes.number,
    /** Height size */
    height: PropTypes.number
};

my package.json devDependencies are:

"devDependencies": {
    "@storybook/addon-actions": "^5.0.0-rc.6",
    "@storybook/addon-info": "^5.0.0-rc.6",
    "@storybook/addon-links": "^5.0.0-rc.6",
    "@storybook/addon-notes": "^5.0.0-rc.6",
    "@storybook/react": "^5.0.0-rc.6",
    "babel-loader": "8.0.5",
    "babel-plugin-react-docgen": "^2.0.2"
  }
@shilman shilman added addon: info cra Prioritize create-react-app compatibility labels Feb 27, 2019
@shilman shilman modified the milestones: v5.0.0, 5.0.x Feb 27, 2019
@sealightPT
Copy link
Author

This problem still exists with
"@storybook/addon-info": "^5.0.1"
and
"react-scripts": "^2.1.8"

@alexandrecanuto
Copy link

Having the same problem here.

@nnquangit
Copy link

nnquangit commented Mar 30, 2019

Storybook 5.0.5 not use babel config in .storybook folder. All plugins like: storybook-readme, @storybook/addon-info will not detect Component.__docgenInfo. So propTypes always empty.

Try update webpack config

config.module.rules.push({
        test: /\.(js|mjs|jsx|ts|tsx)$/,
        exclude: /(node_modules|bower_components)/,
        use: {
            loader: 'babel-loader',
            options: {
                presets: ["@babel/env", "@babel/flow", "@babel/react",],
                plugins: ["react-docgen", "@babel/plugin-proposal-class-properties"]
            }
        }
    });

@stale
Copy link

stale bot commented Apr 20, 2019

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!

@stale stale bot added the inactive label Apr 20, 2019
@stale stale bot removed the inactive label Apr 21, 2019
@mrmckeb
Copy link
Member

mrmckeb commented Apr 21, 2019

The solution that @nnquangit has suggested is good, but I'd suggest you just need to add to plugins, under options - as opposed to adding a whole rule.

I'm not sure what the best way to approach this is, as with CRA we use the CRA config - and don't necessarily want people to add to provide their own Babel configs. I'm definitely open to any ideas here :)

@shilman
Copy link
Member

shilman commented Apr 22, 2019

@mrmckeb can you provide an example?

@mrmckeb
Copy link
Member

mrmckeb commented Apr 22, 2019

Yes, sorry - good thought @shilman - you can see an example of how we do it internally here:
https://github.com/storybooks/storybook/blob/074d0f36da88d740167b1a033d63396e6f04af0b/app/react/src/server/cra-config.js#L172

This is part of PR #5308.

So instead of:

    config.module.rules.push({
        test: /\.(js|mjs|jsx|ts|tsx)$/,
        exclude: /(node_modules|bower_components)/,
        use: {
            loader: 'babel-loader',
            options: {
                presets: ["@babel/env", "@babel/flow", "@babel/react",],
                plugins: ["react-docgen", "@babel/plugin-proposal-class-properties"]
            }
        }
    });

You would do this (I didn't test, but it should be close enough):

const babelRule = config.module.rules.find((rule) => rule.use && rule.use.loader === 'babel-loader');
const otherRules = config.modules.rules.filter((rule) => rule === babelRule);
config.module.rules = [
  ...otherRules,
  {
    ...babelRule,
    use: {
      ...babelRule.use,
      options: {
        ...babelRule.use.options,
        plugins: ['react-docgen', ...babelRule.use.options.plugins],
      },
    }.
  }
];

// Or, if you like to mutate...
const babelRuleIndex = config.module.rules.findIndex((rule) => rule.use && rule.use.loader === 'babel-loader');
config.module.rules[babelRuleIndex].use.options.plugins.push('react-docgen');

@stale
Copy link

stale bot commented May 13, 2019

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!

@stale stale bot added the inactive label May 13, 2019
@shilman shilman removed the inactive label May 13, 2019
@stale
Copy link

stale bot commented Jun 3, 2019

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!

@stale stale bot added the inactive label Jun 3, 2019
@shilman shilman modified the milestones: 5.0.x, 5.1.x Jun 5, 2019
@stale stale bot removed the inactive label Jun 5, 2019
@stale
Copy link

stale bot commented Jun 26, 2019

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!

@stale stale bot added the inactive label Jun 26, 2019
@stale
Copy link

stale bot commented Jul 26, 2019

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

@stale stale bot closed this as completed Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addon: info cra Prioritize create-react-app compatibility has workaround inactive
Projects
None yet
Development

No branches or pull requests

5 participants