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]: Autodocs not working when a React component returns a portal #27169

Open
symsmith opened this issue May 16, 2024 · 4 comments
Open

[Bug]: Autodocs not working when a React component returns a portal #27169

symsmith opened this issue May 16, 2024 · 4 comments

Comments

@symsmith
Copy link

Describe the bug

If a React component returns a portal created by createPortal from react-dom, Autodocs doesn’t retrieve the type information or JSDoc comments from the file.

To Reproduce

https://stackblitz.com/edit/github-cj2wcx?file=src%2Fstories%2FButtonPortal.tsx

ButtonPortal is the same component as Button, but the returned value is wrapped in createPortal. See the difference between Button/Docs and ButtonPortal/Docs

System

Local environment:


  System:
    OS: macOS 14.0
    CPU: (10) arm64 Apple M2 Pro
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
    pnpm: 9.1.1 - ~/Library/pnpm/pnpm <----- active
  Browsers:
    Edge: 124.0.2478.105
    Safari: 17.0
  npmPackages:
    @storybook/addon-actions: ^8.1.1 => 8.1.1 
    @storybook/addon-essentials: ^8.1.1 => 8.1.1 
    @storybook/addon-links: ^8.1.1 => 8.1.1 
    @storybook/addon-onboarding: ^8.1.1 => 8.1.1 
    @storybook/manager-api: ^8.1.1 => 8.1.1 
    @storybook/react: ^8.1.1 => 8.1.1 
    @storybook/react-vite: ^8.1.1 => 8.1.1 
    @storybook/theming: ^8.1.1 => 8.1.1 
    eslint-plugin-storybook: ^0.8.0 => 0.8.0 
    storybook: ^8.1.1 => 8.1.1 

But it works the same way on Stackblitz



### Additional context

Is this normal/documented?

This comment was marked as off-topic.

@github-actions github-actions bot locked and limited conversation to collaborators May 16, 2024
@vanessayuenn vanessayuenn reopened this May 16, 2024
@storybookjs storybookjs unlocked this conversation May 19, 2024
@shilman
Copy link
Member

shilman commented May 19, 2024

This looks like a deficiency of react-docgen which is the tool we use to analyze React components by default in 8.0+.

One workaround is to use the much slower, but more accurate react-docgen-typescript instead but adding the following to .storybook/main.ts:

export default {
  // existing...
  typescript: {
    reactDocgen: 'react-docgen-typescript',
  }
};

@shilman shilman added the sev:S3 label May 19, 2024
@symsmith
Copy link
Author

symsmith commented May 19, 2024

I found another workaround, which is to wrap the createPortal call with a fragment. I still wanted to give notice, because I scratched my head for a while before realizing what was different from my other components/stories.

Basically it looks like the component has to return a React.JSX.Element for Autodocs to work.

@shilman
Copy link
Member

shilman commented May 19, 2024

Thats interesting @symsmith and a better workaround (though still annoying). Hopefully we can come up with a better approach to all this soon...

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

3 participants