storybook icon indicating copy to clipboard operation
storybook copied to clipboard

[Bug]: `react-docgen` not correctly populating Description column if props are `Readonly`

Open federico-ntr opened this issue 11 months ago • 9 comments

Describe the bug

After the latest major update, which brings the new autodocs package react-docgen, the doc table of all of my stories is missing pieces of information. Before it was populating the Description column with the JSDocs of component's props' interface:

interface Props {
  /**
   * Id used to compose ids of sub-components
   */
  id: string;
  /**
   * Name of the document
   */
  docName?: string;
  /**
   * Direct link to the resource
   */
  link: string;
  /**
   * Controls whether the responsive version is shown
   */
  isUnderBreakpoint?: boolean;
  /**
   * Controls whether the buttons are disabled
   */
  disabled?: boolean;
}

Resulted in:

image

After the update it looks like this:

image

As you can see the text I wrote in the JSDocs is missing and the type of the two props with a default is not correctly inferred.

While trying to create a repro I discovered that the issue lies in the use of utility type Readonly<T>. You can open the repro and see docs for Button are badly generated. Remove Readonly and restart sb, you'll see they'll be correctly generated. As a workaround I switched to the old react-docgen-typescript which is handling Readonly correctly.

To Reproduce

https://stackblitz.com/edit/github-inlxfv?file=src%2Fstories%2FButton.tsx

System

Storybook Environment Info:

  System:
    OS: macOS 14.4
    CPU: (8) arm64 Apple M2
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    Yarn: 4.1.1 - ~/.nvm/versions/node/v20.11.1/bin/yarn <----- active
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
  Browsers:
    Safari: 17.4
  npmPackages:
    @storybook/addon-essentials: 8.0.2 => 8.0.2 
    @storybook/addon-interactions: 8.0.2 => 8.0.2 
    @storybook/addon-links: 8.0.2 => 8.0.2 
    @storybook/addon-mdx-gfm: 8.0.2 => 8.0.2 
    @storybook/preview-api: 8.0.2 => 8.0.2 
    @storybook/react: 8.0.2 => 8.0.2 
    @storybook/react-vite: 8.0.2 => 8.0.2 
    msw-storybook-addon: 2.0.0-beta.1 => 2.0.0-beta.1 
    storybook: 8.0.2 => 8.0.2

Additional context

No response

federico-ntr avatar Mar 21 '24 10:03 federico-ntr