storybook: [Bug]: Show code displays `<[object Object]...` instead of component name
Describe the bug
Components that are wrapped with forwardRef
in react are not displaying the proper name in built Storybook, whole working as expected in development mode. Example of what I mean in the image below.
Tried to debug by modifying and logging what is passed here: https://github.com/storybookjs/storybook/blob/next/code/renderers/react/src/docs/jsxDecorator.tsx#L108
and indeed the element is different in dev vs prod.
After digging with the help of @IanVS and @JReinhold found out that this might be an issue with react-docgen-typescript
and tsconfig.json
of the project.
To Reproduce
Visit this link: https://github.com/konsalex/design-system-newline-course/tree/storybook-v7-issue
Clone then:
// Install packages
yarn
yarn workspace @newline-ds/foundation build
yarn workspace @newline-ds/react build
// Build and run
yarn workspace @newline-ds/storybook build-storybook && live-server packages/storybook/storybook-public
### System
```shell
Environment Info:
System:
OS: macOS 13.0
CPU: (10) x64 Apple M1 Max
Binaries:
Node: 16.19.0 - ~/Library/Caches/fnm_multishells/44085_1675428690209/bin/node
Yarn: 3.2.1 - /usr/local/bin/yarn
npm: 8.19.3 - ~/Library/Caches/fnm_multishells/44085_1675428690209/bin/npm
Browsers:
Chrome: 109.0.5414.119
Firefox: 109.0
Safari: 16.1
Additional context
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 6
- Comments: 24 (10 by maintainers)
Hey everyone! This issue is solved in #26566 and will be released soon. Thanks for your patience 🙏
Can confirm this is happening on forwarded refs with
.displayName
set after upgrading to Storybook 8.Adding
displayName
to the component showed me the correct thing in the storybook for meSeems like
.displayName
is now becoming the cause of<[object Object...
in v8.I have the same problem after migrating to 8. Here is a simple example from storybook.
Here it is the auto docs output inside the code section.
<[object Object] variant="default" />
In all stories with arguments for controls, as in the example, we still have the problem after the update.
It’s indeed the displayName that is causing the issue. Removing it works fine but there is obviously a bug or does the V8 implement it with custom Storybook logic based on the imported component name ? I’ve seen no motion of that in the migration guide.
It should not be the case because we must keep the posibility to add the displayName for devtools DOM support for example in some cases.
Indeed, having the same issue after upgrading to Storybook 8 from rc.3. Both with and without
reactDocgen: "react-docgen-typescript",
using webpackReplicated with default
npx create-next-app@latest
andnpx storybook@latest init
tested with and without (because docgen still doesnt support forwardRef) : main.ts
Using Storybook Example Button.tsx
Hey @shilman
So things get a little weird… I setup three identical buttons components. The only differences are
NoForwardRefButton
ForwardRefNoDisplayNameButton
ForwardRefWithDisplayNameButton
I then ran the build with the default options and then with react-docgen-typescript
react-docgen
NoForwardRefButton ForwardRefNoDisplayNameButton ForwardRefWithDisplayNameButton
react-docgen-typescript
NoForwardRefButton ForwardRefNoDisplayNameButton ForwardRefWithDisplayNameButton
I just did a stackblitz to check if it’s still the case in 8.1 alpha, and it is - https://stackblitz.com/edit/github-umceda?file=src%2Fstories%2FButton.tsx,.storybook%2Fmain.ts&preset=node