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

[Bug]: v7 -> v8 controls tab is missing a lot of information #26496

Closed
Tracked by #26606
StephanBijzitter opened this issue Mar 14, 2024 · 16 comments
Closed
Tracked by #26606

[Bug]: v7 -> v8 controls tab is missing a lot of information #26496

StephanBijzitter opened this issue Mar 14, 2024 · 16 comments

Comments

@StephanBijzitter
Copy link
Contributor

StephanBijzitter commented Mar 14, 2024

Describe the bug

v7: (7.6.17)
image

v8: (8.0.0)
image

To Reproduce

Removed a LOT of bloat, but this should do:

import type {Meta, StoryObj} from '@storybook/react';
import {MarkdownEditor} from './MarkdownEditor';

const meta: Meta<typeof MarkdownEditor> = {
    component: MarkdownEditor
};

export default meta;

type Story = StoryObj<typeof MarkdownEditor>;

export const Default: Story = {};

export const Collapsed: Story = {
    args: {
        initialState: 'collapsed'
    }
};

export const Expanded: Story = {
    args: {
        initialState: 'expanded'
    }
};
import React, {useRef, useState} from 'react';
import type {ReactElement, FunctionComponent, FormEventHandler} from 'react';

type MarkdownEditorProps = {

    /**
     * Custom description
     */
    initialState?: 'collapsed' | 'expanded';
    onInput?: FormEventHandler<HTMLDivElement>;
    value?: string;
    initialValue?: string;
};

type MarkdownEditorComponent = FunctionComponent<MarkdownEditorProps>;
type MarkdownEditorElement = ReactElement<MarkdownEditorProps>;

export const MarkdownEditor: MarkdownEditorComponent = ({
    initialState = 'collapsed'
}): MarkdownEditorElement => null;

System

Storybook Environment Info:

  System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-3820 CPU @ 3.60GHz
  Binaries:
    Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 4.1.1 - C:\Program Files\nodejs\yarn.CMD <----- active
    npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (122.0.2365.80)
  npmPackages:
    @storybook/addon-a11y: ^7.6.17 => 7.6.17
    @storybook/addon-console: ^3.0.0 => 3.0.0
    @storybook/addon-essentials: ^7.6.17 => 7.6.17
    @storybook/addon-interactions: ^7.6.17 => 7.6.17
    @storybook/addon-knobs: ^7.0.2 => 7.0.2
    @storybook/addon-links: ^7.6.17 => 7.6.17
    @storybook/addon-toolbars: ^7.6.17 => 7.6.17
    @storybook/blocks: ^7.6.17 => 7.6.17
    @storybook/jest: ^0.2.3 => 0.2.3
    @storybook/react: ^7.6.17 => 7.6.17
    @storybook/react-vite: ^7.6.17 => 7.6.17
    @storybook/test: ^7.6.17 => 7.6.17
    @storybook/test-runner: ^0.17.0 => 0.17.0
    @storybook/testing-library: ^0.2.2 => 0.2.2
    @storybook/testing-react: ^2.0.1 => 2.0.1
    msw-storybook-addon: 2.0.0-beta.1 => 2.0.0-beta.1
    storybook: ^7.6.17 => 7.6.17

Additional context

Switching between the two versions (and restarting storybook dev) is enough to trigger this issue - config and code remains untouched

@Astarosa
Copy link

Astarosa commented Mar 14, 2024

@StephanBijzitter

It seems the autodocs shows only the args that you use in your first story or defined is the Meta object. All args are not displayed by default anymore. Try to add and set a value in one of your stories you will see it.

But for the controls options the problem occurs since they switch from react-docgen-typescript to react-docgen by default.
You can set it dirrectly in your main config under the typescript object but on my side when i do so it's worst ! Options which should be displayed as a select by default are displayed as string and setting up directly with argTypes in the Meta remove the field...

A curious choice...

@federico-ntr
Copy link

@Astarosa explained why you see just an arg, but there are still issues with Description, Default and Control. I managed to get back my Descriptions (which I wrote as JSDocs to my interfaces) by switching to the old react-docgen-typescript

@Astarosa
Copy link

Astarosa commented Mar 14, 2024

@federico-ntr

With no args specified except children by default in the Meta :
image

With an arg specified in THE FIRST story (won't shows up if specified in the second and not in the first) :
image

With default react-docgen :
image

With react-docgen-typescript :
image

All these screenshots are V8 based.
In V7 everything works perfectly so i assume that using react-docgen or react-docgen-typescript is only part of the problem.

@vanessayuenn
Copy link
Contributor

Thanks for reporting this. We switched to using react-docgen for performance reasons. What is the remaining issue that is not solved by specifying to use react-docgen-typescript for docgen?

@Astarosa
Copy link

Thanks for reporting this. We switched to using react-docgen for performance reasons. What is the remaining issue that is not solved by specifying to use react-docgen-typescript for docgen?

For some reasons controls are broken since V8. Change the version of react-docgen doesn't fix it and on my side when i switch back to react-docgen-typescript it interpret my button as this weird _c

@fastndead
Copy link

Hey! This issue happened to me too, luckily switching to react-docgen-typescript solved the problem

@narcecl
Copy link

narcecl commented Mar 26, 2024

Having the same issue after upgrading to 8.0.4 from 7.6.17 :(

@loujonker
Copy link

I'm facing the same issue. It's also hiding the type descriptions. I can manually add them by adding argtypes.field.description but it would be nice if this would be auto generated.

@code-jongleur
Copy link

We have a similar issue, but already on the usual component's documentation page. Our project is based on Storybook 8.0.8, Vite, React, TypeScript.

Here is an example:
MyComponent.tsx:

export interface MyComponentProps {
  /** The name that should be displayed */
  name: string;
}

export const MyComponent = ({ name }: MyComponentProps) => {
  return <div>Hello {name}</div>;
};

MyComponent.story.tsx:

import { Meta, StoryObj } from "@storybook/react";
import { MyComponent } from "./MyComponent";
import { action } from "@storybook/addon-actions";
import { useArgs } from "@storybook/preview-api";

const meta: Meta<typeof MyComponent> = {
  title: "MyComponent",
  component: MyComponent,
  tags: ["autodocs"],
};

export default meta;
type Story = StoryObj<typeof MyComponent>;

export const Preview: Story = {
  args: {
    name: "Fred",
  },
};

Result: there is "string" instead of my JSDoc description "The name that should be displayed" inside the Storybook component's table
image

Adding reactDocgen: "react-docgen-typescript" in the main.ts does not help.

main.ts:

import { resolve } from "path";
const componentsDir = resolve(__dirname, "../src/components");
const globalDir = resolve(__dirname, "../src/global");
const config = {
  stories: ["../CONTRIBUTING.mdx", "../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
  addons: [
    "@storybook/addon-essentials",
    "@storybook/addon-links",
    "@storybook/addon-storysource",
    "@storybook/addon-a11y",
  ],
  core: {},
  reactDocgen: "react-docgen-typescript",
  framework: {
    name: "@storybook/react-vite",
    options: {},
  },
  docs: {
    autodocs: "tag",
    defaultName: "Usage",
  },
  staticDirs: [{ from: "../public/images", to: "/images" }],
  loader: { ".js": "jsx" },
};
export default config;

Any ideas?

@code-jongleur
Copy link

Update: I just found out that I did not configure reactDocgen correctly in the main.ts. It must be

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

With this, I can confirm that the documentation is generated properly.

@Zver64
Copy link

Zver64 commented Apr 17, 2024

Adding reactDocgen: "react-docgen-typescript" in the main.ts does not help.

I noticed that with react-docgen-typescript generates controls only once, when you start storybook. That means that if you change your type annotations in your component props - it will not update controls. You will have to manually restart storybook. Maybe that will help.

@FumbaCloud
Copy link

Same for me. When using react-docgen-typescript, the control seems correct, but it no longer reflects changes in types until rebuilt

@efoken
Copy link

efoken commented Apr 29, 2024

There is some stuff that I found out recently, that might help somebody.

When using forwardRef or memo or HOC, it must be used like this:

export const Button = forwardRef<'button', ButtonProps>((props: ButtonProps) => {

Even if the second ButtonProps is not needed, it has to be props: ButtonProps, otherwise no controls show up.

The declaration of props have to be in a plain interface with no magic:

export interface ButtonProps {
  color?: 'primary' | 'error';
}

This works as expected. But in one big project I use polymorphic components and the props are not declared using a simple interface, they are defined like this:

export interface ButtonOwnProps {
  color?: 'primary' | 'error';
}

export interface ButtonTypeMap<C extends React.ElementType = 'button', P = {}> {
  defaultAs: C;
  props: P & ButtonOwnProps;
}

export type ButtonProps<
  C extends React.ElementType = ButtonTypeMap['defaultAs'],
  P = {},
> = OverrideProps<ButtonTypeMap<C, P>, C>;

This was working with v7 but does not work with Storybook 8 anymore.

Storybook config in main.ts:

For one project I was using docs: false in the config to disable the "Docs" tab completely (because there's an extra documentation website for this).

  addons: [
    '@storybook/addon-a11y',
    {
      name: '@storybook/addon-essentials',
      options: {
        docs: false,
      },
    },
  ],

In v7 this was fine, but if you use the same in Storybook 8 no controls show up. Also it's not needed anymore, so just remove it or set docs: true (which is the default).

RemiBonnet pushed a commit to Qovery/console that referenced this issue May 14, 2024
* chore: move to storybook 8

* chore: replace storybook-tailwind-dark-mode with @storybook/addon-themes

* chore: use react-docgen-typescript instead of react-docgen

https://storybook.js.org/blog/storybook-8/#improved-react-and-vue-control-autogeneration
https://storybook.js.org/docs/api/main-config-typescript#reactdocgen
storybookjs/storybook#26496

* chore: upgrade eslint-plugin-storybook
pwolfert added a commit to CMSgov/design-system that referenced this issue May 17, 2024
Copy link
Contributor

Hi there! Thank you for opening this issue, but it has been marked as stale because we need more information to move forward. Could you please provide us with the requested reproduction or additional information that could help us better understand the problem? We'd love to resolve this issue, but we can't do it without your help!

@github-actions github-actions bot added the Stale label May 21, 2024
Copy link
Contributor

I'm afraid we need to close this issue for now, since we can't take any action without the requested reproduction or additional information. But please don't hesitate to open a new issue if the problem persists – we're always happy to help. Thanks so much for your understanding.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 28, 2024
@daylesalmon
Copy link

daylesalmon commented Jun 5, 2024

There is some stuff that I found out recently, that might help somebody.

When using forwardRef or memo or HOC, it must be used like this:

export const Button = forwardRef<'button', ButtonProps>((props: ButtonProps) => {

Can we get this issue re-opened? As this issue still persists.

I am using forwardRef components, and the only way to get react-docgen to display the descriptions is to do what is mentioned in the above comment (declare the prop types in two places). We shouldn't have to do this though, as the type exists and you should be able to access it via an abstract syntax tree or similar. I'm guessing this is how it was working in v7 with react-docgen-typescript?

For additional context, I expect:

export const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {...}

to show the correct prop descriptions.

pwolfert added a commit to CMSgov/design-system that referenced this issue Jul 12, 2024
* WIP: Try upgrading the react types and working through errors

Here's the summary of errors we're starting with:

```
Found 109 errors in 28 files.

Errors  Files
     4  packages/design-system/src/components/Accordion/Accordion.stories.tsx:8
     3  packages/design-system/src/components/Alert/Alert.stories.tsx:6
     1  packages/design-system/src/components/Autocomplete/utils.tsx:15
    11  packages/design-system/src/components/ChoiceList/ChoiceList.stories.tsx:7
     4  packages/design-system/src/components/Drawer/Drawer.stories.tsx:29
    12  packages/design-system/src/components/Dropdown/Dropdown.stories.tsx:8
     6  packages/design-system/src/components/Dropdown/Dropdown.tsx:171
     1  packages/design-system/src/components/Dropdown/DropdownMenuOption.tsx:66
     5  packages/design-system/src/components/HelpDrawer/HelpDrawer.stories.tsx:29
     4  packages/design-system/src/components/IdleTimeout/IdleTimeout.stories.tsx:10
     4  packages/design-system/src/components/PrivacySettingsDialog/PrivacySettingsDialog.stories.tsx:17
     6  packages/design-system/src/components/Spinner/Spinner.stories.tsx:6
    23  packages/design-system/src/components/TextField/TextField.stories.tsx:10
     2  packages/design-system/src/components/Tooltip/Tooltip.tsx:357
     1  packages/design-system/src/components/UsaBanner/UsaBanner.stories.tsx:5
     1  packages/design-system/src/components/web-components/ds-accordion/ds-accordion.tsx:22
     1  packages/design-system/src/components/web-components/preactement/define.test.tsx:35
     1  packages/docs/src/components/content/ContentRenderer.tsx:111
     1  packages/docs/src/components/content/EmbeddedExample.tsx:17
     2  packages/docs/src/components/layout/SideNav/SideNav.tsx:25
     2  packages/docs/src/components/layout/TableOfContents.tsx:43
     1  packages/docs/src/components/page-templates/BlogPage.tsx:18
     1  packages/docs/src/pages/blog.tsx:33
     2  packages/ds-healthcare-gov/src/components/Accordion/Accordion.stories.tsx:8
     2  packages/ds-medicare-gov/src/components/Card/Card.stories.tsx:6
     5  packages/ds-medicare-gov/src/components/HelpDrawer/HelpDrawer.stories.tsx:31
     1  packages/ds-medicare-gov/src/components/SimpleFooter/SimpleFooter.stories.tsx:6
     2  packages/ds-medicare-gov/src/components/Stars/stars.stories.tsx:6
```

* Fixing the first batch of errors (down to 89 from 109)

* Remove custom docs config for Drawer storybook page and fix VRTs

Add new interaction VRTs for dialog and drawer, and don't have any of the stories open them automatically

* Trying to fix missing Drawer story controls but failing

I was hoping fixing these types would do it.

* Ignore errors coming from react-aria types

* Two different ways of getting around the errors for inlining the doc page JSX

* Down to 24 errors

* Finished fixing all the errors in the core package (down to 20 now)

* Huh, the errors just go away after making some edits to the yarn lockfile

I think I'll go back and undo some of my previous commits to see if I need them

* Just realized there was some dead code in here

* Revert "Ignore errors coming from react-aria types"

This reverts commit f4fac88.

* Revert more of the react-aria changes

This reverts part of commit ffc035d.

* I can revert this change too

* Oh no, these new arg tables do not look good

It seems as though the type inference has gotten worse in this version. Instead of the type for Badge `size` being listed as `big` (only supports big), it is now reported as `literal`. For `string | React.ReactNode`, it only says `union`. Instead of `type` being `checkbox` and `radio`, it’s `union`. Instead of `ReactNode` for `React.ReactNode`, it prints out as `ReactReactNode`

* Revert "Oh no, these new arg tables do not look good"

This reverts commit 6811f4b.

* Changing the default settings to use the typescript docgen results in much fewer changes

See storybookjs/storybook#26496
zarahzachz added a commit to CMSgov/design-system that referenced this issue Jul 24, 2024
* bump storybook to latest packages

* update storybook files using SB migration scripts

* use correct markdown comment structure

* replace ArgsTable with ArgTypes - seems to work

* Fix reading of story files from tests

* Fix old references to `ArgsTable`

* [NO-TICKET] Upgrade React types to fix Storybook 8 branch (#3080)

* WIP: Try upgrading the react types and working through errors

Here's the summary of errors we're starting with:

```
Found 109 errors in 28 files.

Errors  Files
     4  packages/design-system/src/components/Accordion/Accordion.stories.tsx:8
     3  packages/design-system/src/components/Alert/Alert.stories.tsx:6
     1  packages/design-system/src/components/Autocomplete/utils.tsx:15
    11  packages/design-system/src/components/ChoiceList/ChoiceList.stories.tsx:7
     4  packages/design-system/src/components/Drawer/Drawer.stories.tsx:29
    12  packages/design-system/src/components/Dropdown/Dropdown.stories.tsx:8
     6  packages/design-system/src/components/Dropdown/Dropdown.tsx:171
     1  packages/design-system/src/components/Dropdown/DropdownMenuOption.tsx:66
     5  packages/design-system/src/components/HelpDrawer/HelpDrawer.stories.tsx:29
     4  packages/design-system/src/components/IdleTimeout/IdleTimeout.stories.tsx:10
     4  packages/design-system/src/components/PrivacySettingsDialog/PrivacySettingsDialog.stories.tsx:17
     6  packages/design-system/src/components/Spinner/Spinner.stories.tsx:6
    23  packages/design-system/src/components/TextField/TextField.stories.tsx:10
     2  packages/design-system/src/components/Tooltip/Tooltip.tsx:357
     1  packages/design-system/src/components/UsaBanner/UsaBanner.stories.tsx:5
     1  packages/design-system/src/components/web-components/ds-accordion/ds-accordion.tsx:22
     1  packages/design-system/src/components/web-components/preactement/define.test.tsx:35
     1  packages/docs/src/components/content/ContentRenderer.tsx:111
     1  packages/docs/src/components/content/EmbeddedExample.tsx:17
     2  packages/docs/src/components/layout/SideNav/SideNav.tsx:25
     2  packages/docs/src/components/layout/TableOfContents.tsx:43
     1  packages/docs/src/components/page-templates/BlogPage.tsx:18
     1  packages/docs/src/pages/blog.tsx:33
     2  packages/ds-healthcare-gov/src/components/Accordion/Accordion.stories.tsx:8
     2  packages/ds-medicare-gov/src/components/Card/Card.stories.tsx:6
     5  packages/ds-medicare-gov/src/components/HelpDrawer/HelpDrawer.stories.tsx:31
     1  packages/ds-medicare-gov/src/components/SimpleFooter/SimpleFooter.stories.tsx:6
     2  packages/ds-medicare-gov/src/components/Stars/stars.stories.tsx:6
```

* Fixing the first batch of errors (down to 89 from 109)

* Remove custom docs config for Drawer storybook page and fix VRTs

Add new interaction VRTs for dialog and drawer, and don't have any of the stories open them automatically

* Trying to fix missing Drawer story controls but failing

I was hoping fixing these types would do it.

* Ignore errors coming from react-aria types

* Two different ways of getting around the errors for inlining the doc page JSX

* Down to 24 errors

* Finished fixing all the errors in the core package (down to 20 now)

* Huh, the errors just go away after making some edits to the yarn lockfile

I think I'll go back and undo some of my previous commits to see if I need them

* Just realized there was some dead code in here

* Revert "Ignore errors coming from react-aria types"

This reverts commit f4fac88.

* Revert more of the react-aria changes

This reverts part of commit ffc035d.

* I can revert this change too

* Oh no, these new arg tables do not look good

It seems as though the type inference has gotten worse in this version. Instead of the type for Badge `size` being listed as `big` (only supports big), it is now reported as `literal`. For `string | React.ReactNode`, it only says `union`. Instead of `type` being `checkbox` and `radio`, it’s `union`. Instead of `ReactNode` for `React.ReactNode`, it prints out as `ReactReactNode`

* Revert "Oh no, these new arg tables do not look good"

This reverts commit 6811f4b.

* Changing the default settings to use the typescript docgen results in much fewer changes

See storybookjs/storybook#26496

* update vrt snaps, drawer stories renamed

* [NO-TICKET] Use new docgen union sorting (#3166)

* Use the new beta version of `react-docgen-typescript` that has union-member sorting

Right now I'm trying to figure out why the prop table on the Drawer page isn't rendering

* The arg table was gone because it wasn't included in the template

* Update VRT changes from this branch with underline style changes from `main`

* Go back to the Drawer story setup from c930062

In the interaction tests, we were trying to use features of the story (the toggle) that didn't exist, which is why they were failing. I think the original reason I changed the drawer stories was to make them consistent with the dialog stories, and I was also able to consolidate them down to one. That necessitated the interaction tests because the drawer was no longer open by default for a screenshot to be taken.

---------

Co-authored-by: Patrick Wolfert <patrick.wolfert@adhocteam.us>
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