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

Addon-docs: Fix exotic React components in Source block #12638

Merged
merged 10 commits into from Oct 5, 2020

Conversation

andezzat
Copy link
Member

@andezzat andezzat commented Oct 1, 2020

The Problem

React Memo & ForwardRef exotic components would show up in the code snippet of storybook as <[object Object]> because it didn't know where to lookup the inner render function's name.

This is a bug in the library Storybook uses to render JSX into a string: algolia/react-element-to-jsx-string#352

What I did

I stole the default displayNameFn from the original library here
And added what it needed to fetch Memo & ForwardRef component's names.

How to test

  • Is this testable with Jest or Chromatic screenshots?
    Maybe? I have no idea
  • Does this need a new example in the kitchen sink apps?
    No
  • Does this need an update to the documentation?
    No

If your answer is yes to any of these, please make sure to include it in your PR.

…/ memo & forwardRef exotic components

Prev. would just do as <[object Object]>.. because it didn't know where to lookup the inner render function's name.
@andezzat andezzat changed the title fix(react/jsxDecorator): displayName works for exotic components fix(react/jsxDecorator): displayName for exotic components Oct 1, 2020
@ndelangen ndelangen self-assigned this Oct 1, 2020
@andezzat andezzat requested a review from usulpro as a code owner October 3, 2020 06:33
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @andezzat !! Thanks so much for putting this together -- will make a ton of people happy. Unfortunately, I added a test case to official-storybook and it doesn't seem to be working end-to-end. You can find that in the latest commit on this branch.

Would you mind:

  • looking into this specific case
  • adding more test cases to official-storybook
  • reconciling the official-storybook behavior and the jest test cases (look great, but somehow don't line up)

@shilman shilman changed the title fix(react/jsxDecorator): displayName for exotic components Addon-docs: Fix displayName for exotic React components in Source block Oct 3, 2020
@shilman shilman changed the title Addon-docs: Fix displayName for exotic React components in Source block Addon-docs: Fix exotic React components in Source block Oct 3, 2020
…xample

Component should be fed directly to React.memo|forwardRef functions so that displayName is set. Previously was passing an anonymous arrow fn...
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 💯 💯 💯

@shilman shilman merged commit 4f580d7 into storybookjs:next Oct 5, 2020
@shilman shilman added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Oct 5, 2020
@shilman shilman added this to the 6.0.x milestone Oct 5, 2020
@shilman shilman added the patch:done Patch/release PRs already cherry-picked to main/release branch label Oct 5, 2020
shilman added a commit that referenced this pull request Oct 5, 2020
Addon-docs: Fix exotic React components in Source block
@andezzat andezzat deleted the fix/react-component-name branch October 5, 2020 08:12
@ghengeveld
Copy link
Member

ghengeveld commented Oct 9, 2020

This appears to be broken:

Screenshot 2020-10-09 at 14 05 32

It seems to originate from ForwardRefButtonInnerPropTypes which wraps a button component directly in forwardRef, which is not allowed.

export const ForwardRefButtonInnerPropTypes = forwardRef(BaseButton);

BaseButton is a component with propTypes and defaultProps.

@shilman
Copy link
Member

shilman commented Oct 9, 2020

cc @andezzat can you take a look ☝️

@andezzat
Copy link
Member Author

andezzat commented Oct 10, 2020

Ah yes, I should've made a new component w/ proper forwardRef render fn args than passing BaseButton as-is 😂
PR: #12733

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addon: docs block: source bug patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants