storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
84.09k stars 9.25k forks source link

[Bug]: 8.0.alpha default reactDocgen generates different output than in 7.x #25059

Open csantos1113 opened 10 months ago

csantos1113 commented 10 months ago

Describe the bug

react-docgen generates different (and incomplete) documentation than react-docgen-typescript; and once #24165 lands the default documentation generated by Storybook will be significantly "bad" for typescript users using typescript path aliases and enums.

EDIT (@valentinpalkovic):

Originally posted by @csantos1113 in https://github.com/storybookjs/storybook/issues/24165#issuecomment-1832420070

To Reproduce

  1. Go to https://stackblitz.com/edit/github-aca5uv-867pnb (EDIT: Path aliases are now supported)
    • Notes:
    • this rep example uses typescript path aliases which are pretty common.
    • it also uses vite-tsconfig-paths for those paths to resolve in vite
    • it uses react-docgen (which will be the default in 8.0 once #24165 is merged)
    • ⚠️ Notice:
    • The documentation is "unknown"
    • "controls" are broken
    • props documentation is gone
    • required props are gone
  2. Go to https://stackblitz.com/edit/github-aca5uv-867pnb
    • Notes:
    • this rep example does not use typescript path aliases. It's just relative imports
    • it uses react-docgen (which will be the default in 8.0 once #24165 is merged)
    • ⚠️ Notice:
    • The documentation show up
    • required props show up
    • "controls" are still broken for enum values
  3. Go to https://stackblitz.com/edit/github-aca5uv-xws82c
    • Notes:
    • this reg example is the same as number 1 with path aliases and vite-tsconfig-paths
    • but it uses react-docgen-typescript instead
    • 😍 Notice:
    • The documentation show up
    • required props show up
    • "controls" work fine for all types even enum values

System

`^8.0.0-alpha.0`, but also happening in `v7.x`.

Additional context

I understand there are foundational differences between the two libraries, and react-docgen has a bunch of open TypeScript related issues: https://github.com/reactjs/react-docgen/issues?q=is%3Aissue+is%3Aopen+typescript and the decision behind Storybook swapping the default docsgen library, and that keeping these 2 libraries working "the same" is not responsibility of the Storybook team ❤️

This is not really an issue with storybook per se, but the Storybook team might help push this forward in the right direction 🙏

I'm opening this issue per @shilman request: https://github.com/storybookjs/storybook/pull/24165#issuecomment-1833012165

Related issues

### Related issues at react-docgen
- [ ] https://github.com/reactjs/react-docgen/issues/456 
- [ ] https://github.com/reactjs/react-docgen/issues/877
shilman commented 9 months ago

@valentinpalkovic it would be great if we could support tsconfig paths in the react-docgen resolver for both webpack & vite. WDYT?

valentinpalkovic commented 9 months ago

Relates to https://github.com/reactjs/react-docgen/issues/456.

@shilman we could indeed try to provide a custom importer, which handles path aliases, or someone/we contribute directly to react-docgen.

valentinpalkovic commented 6 months ago

At least https://github.com/reactjs/react-docgen/issues/456 was fixed in Storybook by adjusting react-docgen's default resolver.

It will be part of the next 8.0.0-rc.2 prerelease!

macrozone commented 6 months ago

react-docgen also does not seem to work in my setup:

"use client";
import {
  Button as ButtonBase,
  ButtonText,
  ButtonIcon,
  ButtonSpinner,
} from "theme";
import type { ComponentProps } from "react";

export type ButtonProps = { title: string } & Pick<
  ComponentProps<typeof ButtonBase>,
  "onPress" | "variant" | "action" | "size"
> & {
    Icon?: ComponentProps<typeof ButtonIcon>["as"];
    processing?: boolean;
  };
export const Button = ({ title, Icon, processing, ...rest }: ButtonProps) => {
  return (
    <ButtonBase {...rest}>
      <ButtonText>{title}</ButtonText>

      {Icon ? <ButtonIcon as={Icon} /> : null}
      {processing ? <ButtonSpinner /> : null}
    </ButtonBase>
  );
};
import type { Meta, StoryObj } from "@storybook/react";

import { Button } from "./Button";

export default {
  title: "primitives/Button",
  component: Button,

  parameters: {
 layout
    layout: "centered",
  },

docs/autodocs
  tags: ["autodocs"],
 };

type Story = StoryObj<typeof Button>;

export const Default: Story = {
  args: {
    title: "Button",
  },
};

Bildschirmfoto 2024-03-11 um 13 15 21

Bildschirmfoto 2024-03-11 um 13 16 39


i am unsure whether it is a problem similar to https://github.com/reactjs/react-docgen/issues/456 or something else