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

Props slot not render right in Stories when use optional chain in component. #11883

Closed
uni-zheng opened this issue Aug 11, 2020 · 12 comments
Closed

Comments

@uni-zheng
Copy link

Describe the bug
Props slot not render right in Stories(or MDX) when use optional chain in component.

There is [No props found for this component] placeholder in props slot. And props slot render right content when removed optional chain.

image

image

Code snippets

// .storybook/main.js
const path = require('path');

module.exports = {
  stories: [
    '../packages/**/*.stories.(ts|js|mdx)',
  ],

  addons: [
    {
      name: '@storybook/addon-docs',
      options: {
        configureJSX: true,
        babelOptions: {
          'plugins': [
            '@babel/plugin-proposal-class-properties',
            '@babel/plugin-proposal-optional-chaining',
            '@babel/plugin-proposal-nullish-coalescing-operator',
            '@babel/plugin-proposal-export-default-from',
            '@babel/plugin-proposal-object-rest-spread',
          ],
        },
      },
    },
    '@storybook/addon-knobs',
    '@storybook/addon-a11y',
    '@storybook/addon-viewport',
    '@storybook/addon-backgrounds',
    '@storybook/addon-storysource',
  ],

  webpackFinal: async (config) => {
    config.module.rules.push({
      test: /\.scss$/,
      use: [
        'style-loader',
        'css-loader',
        {
          loader: 'sass-loader',
          options: {
            implementation: require('sass'),
          },
        },
      ],
      include: path.resolve(__dirname, '../'),
    });

    return config;
  },
};
// button.stories.js
import React from 'react';
import Button from '../Button.js';
import '../style/index.scss';

export default {
  title: 'ZUI/Button',
  component: Button,
};

export const Base = () => (
  <Button>base</Button>
);

System:

 System:
    OS: macOS 10.15.6
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  Binaries:
    Node: 12.18.2 - /usr/local/bin/node
    Yarn: 1.16.0 - /usr/local/bin/yarn
    npm: 6.14.5 - /usr/local/bin/npm
  Browsers:
    Chrome: 84.0.4147.105
    Safari: 13.1.2
  npmPackages:
    @storybook/addon-a11y: ^5.3.19 => 5.3.19 
    @storybook/addon-backgrounds: ^5.3.19 => 5.3.19 
    @storybook/addon-docs: ^5.3.19 => 5.3.19 
    @storybook/addon-knobs: ^5.3.19 => 5.3.19 
    @storybook/addon-storysource: ^5.3.19 => 5.3.19 
    @storybook/addon-viewport: ^5.3.19 => 5.3.19 
    @storybook/react: ^5.3.19 => 5.3.19 

Additional context
I added @babel/plugin-proposal-optional-chaining in addons config but it's not working.

@shilman
Copy link
Member

shilman commented Aug 18, 2020

I'm guessing this is a problem with react-docgen which is what generates the docgen info from your source. Might you be able to file an issue there?

@uni-zheng
Copy link
Author

Here is I found reactjs/react-docgen#463

@joeycozza
Copy link
Contributor

So yeah, looks like babel made a change that was intentional, and ast-types needs to make an update. benjamn/ast-types#383

One potential work around that is suggested here reactjs/react-docgen#463 is to pin the babel/core and babel/parser versions to 7.10.5. I don't know if that is the best course of action for storybook to take though. Maybe we just wait it out to get resolved itself?

@stale
Copy link

stale bot commented Sep 11, 2020

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 Sep 11, 2020
@ethancrook99
Copy link

ast-types has updated this! There is currently a PR for react-docgen to update their dependencies, I'll make a PR here to update to the newest react-docgen when that change is merged.

@stale stale bot removed the inactive label Sep 14, 2020
@ethancrook99
Copy link

It looks like storybook doesn't need any updates for this to work--as far as I can tell, all that's left is for anyone with this issue to update any local dependencies on react-docgen to the latest version (5.3.0)

@idbartosz
Copy link

I'm experiencing same issue with Storybook v6.0.21 after clearing up package-lock file. Now, whenever component uses optional chaining I get

Screen Shot 2020-09-28 at 19 16 13

Any quick fix for that (other than keeping old package-lock)? I'm not using explicitly react-docgen only addon-docs.


I've checked the bare bones npx sb init --type react and it also breaks there. A bit more gracefully than my customized one but still it breaks with optional chaining 😉

2020-09-28 20-11-45 2020-09-28 20_12_43

CC @shilman @ethancrook99

@shilman
Copy link
Member

shilman commented Sep 28, 2020

@idbartosz looks like it's fixed in react-docgen reactjs/react-docgen#463

@idbartosz
Copy link

@shilman so this will be fixed in next SB release because I see fix was merged on their side?

@shilman
Copy link
Member

shilman commented Sep 28, 2020

Once they release and you upgrade. React-docgen is not a direct dependency so i don't think storybook needs to do anything.

@shilman
Copy link
Member

shilman commented Oct 15, 2020

Yo-ho-ho!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.1.0-alpha.24 containing PR #12748 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Oct 15, 2020
@shilman
Copy link
Member

shilman commented Oct 23, 2020

Yo-ho-ho!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.27 containing PR #12748 that references this issue. Upgrade today to the @latest NPM tag to try it out!

npx sb upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants