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]: docgen bug with export default function ... #21145

Closed
jdelStrother opened this issue Feb 17, 2023 · 3 comments · Fixed by #21147 or #21380
Closed

[Bug]: docgen bug with export default function ... #21145

jdelStrother opened this issue Feb 17, 2023 · 3 comments · Fixed by #21147 or #21380
Assignees

Comments

@jdelStrother
Copy link

jdelStrother commented Feb 17, 2023

Describe the bug

Storybook 7 beta49 generates javascript containing things like:

try {
    // @ts-ignore
    DefaultButton.displayName = "DefaultButton";
    // @ts-ignore
    default.__docgenInfo = { "description": "", "displayName": "DefaultButton", "props": { "label": { "defaultValue": null, "description": "", "name": "label", "required": true, "type": { "name": "string" } } } };
    // @ts-ignore
    if (typeof STORYBOOK_REACT_CLASSES !== "undefined")
        // @ts-ignore
        STORYBOOK_REACT_CLASSES["src/stories/DefaultButton.tsx#DefaultButton"] = { docgenInfo: DefaultButton.__docgenInfo, name: "DefaultButton", path: "src/stories/DefaultButton.tsx#DefaultButton" };
}
catch (__react_docgen_typescript_loader_error) { }

which cause the browser to fail parsing with Unexpected keyword 'default'. Expected a closing '}' at the end of a block statement.

It occurs when writing default exports like this -

export default function DefaultButton(p: Props) {
    return <button>{p.label}</button>
}

but can be avoided by separating out the export:

function DefaultButton(p: Props) {
    return <button>{p.label}</button>
}
export default DefaultButton

To Reproduce

Checkout https://github.com/jdelStrother/storybook-snapshots, run yarn && yarn storybook, view in browser

System

Environment Info:

  System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 16.18.1 - /etc/profiles/per-user/jon/bin/node
    Yarn: 1.22.19 - /nix/store/imzxd8mj6airij3v9xh8yddvhzbvvv9n-yarn-1.22.19/bin/yarn
    npm: 8.19.2 - /etc/profiles/per-user/jon/bin/npm
  Browsers:
    Chrome: 109.0.5414.119
    Safari: 16.2
  npmPackages:
    @storybook/addon-essentials: ^7.0.0-beta.49 => 7.0.0-beta.49 
    @storybook/addon-interactions: ^7.0.0-beta.49 => 7.0.0-beta.49 
    @storybook/addon-links: ^7.0.0-beta.49 => 7.0.0-beta.49 
    @storybook/addon-storyshots: ^7.0.0-beta.49 => 7.0.0-beta.49 
    @storybook/blocks: ^7.0.0-beta.49 => 7.0.0-beta.49 
    @storybook/react: ^7.0.0-beta.49 => 7.0.0-beta.49 
    @storybook/react-webpack5: ^7.0.0-beta.49 => 7.0.0-beta.49 
    @storybook/testing-library: ^0.0.14-next.1 => 0.0.14-next.1

Additional context

This is presumably an issue with react-docgen-typescript/react-docgen-typescript-plugin, but thought it was worth highlighting here since the same code works fine in Storybook v6 and v7 beta 45. (I assume the issue is introduced here: #21095)

@shilman
Copy link
Member

shilman commented Feb 17, 2023

Shiver me timbers!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-beta.50 containing PR #21147 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb@next upgrade --prerelease

@shilman
Copy link
Member

shilman commented Feb 17, 2023

Will try to fix in the library and try again

@shilman
Copy link
Member

shilman commented Mar 3, 2023

Gadzooks!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-beta.61 containing PR #21380 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb@next upgrade --prerelease

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
2 participants