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]: 8.0.alpha default reactDocgen generates different output than in 7.x #25059

Open
2 tasks
csantos1113 opened this issue Nov 30, 2023 · 4 comments
Open
2 tasks

Comments

@csantos1113
Copy link

csantos1113 commented Nov 30, 2023

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

  • Storybook has added TypeScript Path Aliases support when used with react-docgen

Originally posted by @csantos1113 in #24165 (comment)

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 React: Set react-docgen to default TS docgen #24165 is merged)
  • ⚠️ Notice:
    • The documentation is "unknown"
    • "controls" are broken
    • props documentation is gone
    • required props are gone
  1. Go to https://stackblitz.com/edit/github-aca5uv-867pnb
  • Notes:
  • ⚠️ Notice:
    • The documentation show up
    • required props show up
    • "controls" are still broken for enum values
  1. 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: #24165 (comment)

Related issues

Related issues at react-docgen

  1. new feature
@shilman
Copy link
Member

shilman commented Dec 25, 2023

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

@shilman shilman added the sev:S2 label Dec 25, 2023
@shilman shilman added this to the 8.0 breaking changes milestone Dec 25, 2023
@valentinpalkovic
Copy link
Contributor

Relates to reactjs/react-docgen#456.

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

@valentinpalkovic
Copy link
Contributor

valentinpalkovic commented Mar 5, 2024

At least reactjs/react-docgen#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
Copy link
Contributor

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

  • i have a monorepo setup, with "ui" (where storybook lives) and a "theme" package
  • the "theme" package only contains components from gluestack, its basically just a package containing the ejected gluestack library
  • the "ui" package declares its own components which are composed from "theme"-components, for example a Button
"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>
  );
};
  • the story:
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",
  },
};

  • when i use "react-docgen", i only see the explicitly set props from the typescript types:

Bildschirmfoto 2024-03-11 um 13 15 21

  • when i use "react-docgen-typescript" i see all props:

Bildschirmfoto 2024-03-11 um 13 16 39


i am unsure whether it is a problem similar to reactjs/react-docgen#456 or something else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Empathy Backlog
Status: No status
Development

No branches or pull requests

5 participants