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

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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 16 (3 by maintainers)

Commits related to this issue

Most upvoted comments

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.

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).

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.

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.