Skip to content

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

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

Open
federico-ntr opened this issue Mar 21, 2024 · 11 comments

Comments

@federico-ntr
Copy link

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

@skorenb
Copy link

skorenb commented Jun 19, 2024

I also encounter the problem when i use forwardRef from react:

const ReactComponent = forwardRef<HTMLDivElement, MyProps>(props, ref) => { ... };

There aren't description content in controls tab and i see uknown type on some arguments.

So i have to assign the type to props argument explicitly to get it working well:

const ReactComponent = forwardRef<HTMLDivElement, MyProps>(props: MyProps, ref) => { ... };

@ajkl2533
Copy link
Contributor

ajkl2533 commented Aug 6, 2024

I also hit this issue while using forwardRef (repro: https://stackblitz.com/edit/github-rccvwa?file=src%2Fstories%2FForwardedButton.stories.ts).
This is extremely problematic for component libraries because after upgrading to v8 we lost lots of documentation.

This is related to #26496

Following examples are for:

export type SurfaceProps = {
  children: ReactNode;
  /** Background of the surface box */
  background?: (typeof SurfaceBackgrounds)[number];
  /** Corner rounding of the surface box */
  radius?: (typeof SurfaceRadii)[number];
  /** Size of the box shadow. Takes and integer, Bigger value, bigger size of the shadow */
  elevation?: number;
  /** Show border around the surface box */
  hasBorder?: boolean;
  /**
   * Switch color scheme for light or dark backgrounds
   *
   * @deprecated Replaced with design tokens for using dark mode add .dark classname
   * to Surface or its parent
   */
  mode?: (typeof SurfaceMode)[number];
} & ComponentPropsWithoutRef<'div'>;




const Surface = forwardRef<HTMLDivElement, SurfaceProps>(( props, ref ) => {
    ...
);

V7 or V8 with { typescript: { reactDocgen: "react-docgen-typescript" } }

Screenshot 2024-08-06 at 9 50 33

V8

Screenshot 2024-08-06 at 9 51 14

V8 with reassigning types to props (const Surface = forwardRef<HTMLDivElement, SurfaceProps>((props: SurfaceProps, ref) => {)

Screenshot 2024-08-06 at 9 51 41

@Charismara
Copy link

Is there any progress on this?

@shilman
Copy link
Member

shilman commented Oct 13, 2024

This is an issue in react-docgen.

reactjs/react-docgen#905

Please help fix the issue there or, if you can't wait for the fix, please use react-docgen-typescript, which is still supported in Storybook.

https://storybook.js.org/docs/api/main-config/main-config-typescript

@Charismara
Copy link

This is an issue in react-docgen.

reactjs/react-docgen#905

Please help fix the issue there or, if you can't wait for the fix, please use react-docgen-typescript, which is still supported in Storybook.

https://storybook.js.org/docs/api/main-config/main-config-typescript

I run into this problem even with react-docgen-typescript. Someone seems to have the same issue here: #29340

@shilman
Copy link
Member

shilman commented Oct 13, 2024

@Charismara Is that issue related to Readonly properties or is it about including properties from node_modules?

@Charismara
Copy link

Charismara commented Oct 14, 2024

@Charismara Is that issue related to Readonly properties or is it about including properties from node_modules?

I suppose it is mainly about including properties from the node_modules but a bunch of those props are string literals

@ChristianRaoulis
Copy link

Any progress on this?

@matricali
Copy link

Up

1 similar comment
@helpIneedAname
Copy link

Up

@Charismara
Copy link

It looks like pnpm is causing that issue for me.

I tested it with Bun and npm and both times all props showed up.

@vanessayuenn vanessayuenn added this to the 9.0 RC milestone Mar 27, 2025
@vanessayuenn vanessayuenn modified the milestones: 9.0-RC, 9.0 GA Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

9 participants