Skip to content

Conversation

@yannbf
Copy link
Member

@yannbf yannbf commented Jan 19, 2021

Issue:
When mistakenly a user writes a story such as:

export const Basic = <div>Hello</div>

rather than:

export const Basic = () => <div>Hello</div>

Storybook fails with an error that is not very helpful:
image

What I did

This PR adds a check in the client api that will break Storybook if the story received is not a function telling exactly which story is broken. It's a similar mechanism than the one that checks if storyName is not a string.

Here's how it looks like:
image

I personally find it quite useful that Storybook breaks entirely because it tells the users that there is a critical error given that their stories are broken and it forces them to fix the problem right away.

How to test

1 - check the branch
2 - yarn build client-api
3 - add this to any of the example stories:

export const Basic = <div>Hello</div>

4 - run Storybook (e.g. yarn start)

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

- Sometimes people make a silly mistake of not passing a function as a story
it might take some time to figure that out, so this adds a helpful error
@yannbf yannbf added maintenance User-facing maintenance tasks preview-api labels Jan 19, 2021
@yannbf yannbf self-assigned this Jan 19, 2021
Copy link
Member

@gaetanmaisse gaetanmaisse left a comment

Choose a reason for hiding this comment

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

Useful and clean 💪🏻 👏🏻

@shilman shilman changed the title fix(client-api): throw an error for invalid story format Core: Throw an error for invalid story format Jan 22, 2021
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.

Great fix Yann 👍 👍 👍

@shilman shilman merged commit 32cd74a into next Jan 22, 2021
@shilman shilman deleted the fix/throw-error-invalid-stories branch January 22, 2021 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance User-facing maintenance tasks preview-api

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants