turbo icon indicating copy to clipboard operation
turbo copied to clipboard

Storybook props table does no appear on provided `design-system` example

Open vimtor opened this issue 3 years ago • 8 comments

What version of Turborepo are you using?

1.4.3

What package manager are you using / does the bug impact?

npm, Yarn v1

What operating system are you using?

Mac

Describe the Bug

Storybook props table does not load on the provided examples/design-system.

CleanShot 2022-08-16 at 18 07 10@2x

Expected Behavior

The props table should appear.

To Reproduce

  1. Clone and run the examples/design-system folder
  2. npm run dev
  3. Navigate to the Docs

vimtor avatar Aug 16 '22 16:08 vimtor

I've found that running the following works:

turbo run dev --filter=docs

vimtor avatar Aug 17 '22 11:08 vimtor

@vimtor did you have an example Button component or was is the default repo version?

Ne-Ne avatar Aug 19 '22 11:08 Ne-Ne

@vimtor did you have an example Button component or was is the default repo version?

It was the default repo version

vimtor avatar Aug 19 '22 14:08 vimtor

@vimtor Interesting even when I update all storybook deps I get nothing, no error just got this "as-is".

However, if you move this storybook away from docs and load storybook into the UI library it works fine.

Screenshot 2022-08-19 at 12 07 25

Ne-Ne avatar Aug 19 '22 15:08 Ne-Ne

I imagine it's a problem with @storybook/builder-vite and react-docgen-typescript. Adding the following to my .storybook/main.js results in the props appearing for now however, I would prefer to use react-docgen-typescript.

  typescript: {
    reactDocgen: "react-docgen",
  },

erickreutz avatar Sep 13 '22 01:09 erickreutz

@erickreutz I use the webpack5 builder and have the same issue.

la55u avatar Sep 13 '22 07:09 la55u

Digging into this further this morning. I found two issues preventing the args table from working. I suspected that react-docgen-typescript wasn't picking up the .ts outside of the docs repo. Adding "../../packages/**/*.{ts,tsx}" as an include to the reactDocgenTypescriptOptions in main.js fixed this issue. The second issue is that Button defines a single prop of children. Looking at the docs for react-docgen-typescript the option skipChildrenPropWithoutDoc defaults to true. In order for children to show up, I needed to set that to false.

My typescript config is as follows:

  typescript: {
    reactDocgen: "react-docgen-typescript",
    reactDocgenTypescriptOptions: {
      shouldExtractLiteralValuesFromEnum: true,
      skipChildrenPropWithoutDoc: false,
      propFilter: (prop) =>
        prop.parent ? !/node_modules/.test(prop.parent.fileName) : true,
      include: ["../../packages/**/*.{ts,tsx}"],
    },
  },

erickreutz avatar Sep 13 '22 17:09 erickreutz

  typescript: {
    reactDocgen: "react-docgen-typescript",
    reactDocgenTypescriptOptions: {
      shouldExtractLiteralValuesFromEnum: true,
      skipChildrenPropWithoutDoc: false,
      propFilter: (prop) =>
        prop.parent ? !/node_modules/.test(prop.parent.fileName) : true,
      include: ["../../packages/**/*.{ts,tsx}"],
    },
  },

@erickreutz Thank you, it kind of works (showing the name and control of the props) but the description of the props and and the description of the component itself is still missing.:/

la55u avatar Sep 13 '22 21:09 la55u

So for anyone interested, I've figured out a solution that is working as intended. Hope it helps 👍

The important part here is the "include" option within main.ts.

I'm using pnpm v7, my stories are within a directory called "stories", co-located where my component are living.

main.ts

const config = {
  "stories": [
    "../node_modules/@acme/core/src/**/stories/*.stories.@(ts|tsx|mdx)"
  ],
  "addons": [
    "@storybook/addon-links",
    "@storybook/addon-essentials",
    "@storybook/addon-interactions",
  ],
  "framework": {
    "name": "@storybook/react-vite",
    "options": {}
  },
  "core": {
    "disableTelemetry": true,
  },
  "typescript": {
    reactDocgenTypescriptOptions: {
      include: ["../core/**/*.{ts,tsx}"] // this is the important part here
    },
    "skipBabel": true,
    "check": false,
  },
  "docs": {
    "autodocs": true // "tag"
  }
};

export default config;

package.json

{
  "name": "docs",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "storybook": "storybook dev -p 6006",
    "build": "storybook build",
    "clean": "rm -rf .turbo && rm -rf node_modules",
    "build-storybook": "storybook build"
  },
  "dependencies": {
    "@acme/core": "workspace:*",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@storybook/addon-essentials": "^7.0.0-beta.44",
    "@storybook/addon-interactions": "^7.0.0-beta.44",
    "@storybook/addon-links": "^7.0.0-beta.44",
    "@storybook/blocks": "^7.0.0-beta.44",
    "@storybook/react": "^7.0.0-beta.44",
    "@storybook/react-vite": "^7.0.0-beta.44",
    "@storybook/testing-library": "^0.0.14-next.1",
    "@types/react": "^18.0.27",
    "@types/react-dom": "^18.0.10",
    "storybook": "^7.0.0-beta.44",
    "typescript": "^4.9.3"
  }
}

mrtnbroder avatar Feb 08 '23 23:02 mrtnbroder