Skip to content

Specific displayName causes syntax error #18074

@Chupriarti

Description

@Chupriarti

Describe the bug
If react component displayName contains "-" than where will be error in preview: Uncaught SyntaxError: Invalid left-hand side in assignment because it builds in this code:

try {
    // @ts-ignore
    my-button-name.displayName = "my-button-name";
    // @ts-ignore

To Reproduce

  1. Install create-react-app with typescript
  2. Install storybook with webpack5 support
  3. In sample component "src\stories\Button.tsx" set displayName like this:
  4. Button.displayName = 'my-button-name'
  5. run storybook
  6. storybook preview won't load (stops at loading state) and in console will be error messages:
    Uncaught SyntaxError: Invalid left-hand side in assignment
    displayName

System
Environment Info:

System:
OS: Windows 10 10.0.19044
CPU: (8) x64 Intel(R) Xeon(R) CPU E3-1230 V2 @ 3.30GHz
Binaries:
Node: 16.14.2 - C:\tools\nodejs\node.EXE
npm: 8.5.0 - C:\tools\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0), Chromium (100.0.1185.50)
npmPackages:
@storybook/addon-actions: ^6.4.22 => 6.4.22
@storybook/addon-essentials: ^6.4.22 => 6.4.22
@storybook/addon-interactions: ^6.4.22 => 6.4.22
@storybook/addon-links: ^6.4.22 => 6.4.22
@storybook/builder-webpack5: ^6.4.22 => 6.4.22
@storybook/manager-webpack5: ^6.4.22 => 6.4.22
@storybook/node-logger: ^6.4.22 => 6.4.22
@storybook/preset-create-react-app: ^4.1.0 => 4.1.0
@storybook/react: ^6.4.22 => 6.4.22
@storybook/testing-library: ^0.0.11 => 0.0.11

Additional context
I am using Framework7 and for some reason I have to add ListItem.displayName = "f7-list-item" in components. Removing this line or modifing it to something like ListItem.displayName = "f7_list_item" fixes syntaxError, but it breakes styles.
Is there anyway to use "f7-list-item" as display name? May be some babel config changing?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions