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

loadStory does not account for reserved story names #32

Open
anicholls opened this issue Jul 5, 2021 · 2 comments
Open

loadStory does not account for reserved story names #32

anicholls opened this issue Jul 5, 2021 · 2 comments

Comments

@anicholls
Copy link
Contributor

After doing some digging in the Storybook source code it looks like they sanitize/rename stories if the name of the story 1. starts with a number, or 2. uses a reserved name in javascript (e.g. delete, default, const, etc.). I started to work on a PR for this, but ran into some issues due to how Storybook treats CSF vs. MDX stories. Unfortunately it seems like Storybook treats these two inconsistently:

For CSF stories:

  • Stories with reserved keyword names (e.g. Delete) are not touched (URL is unaffected)
  • Stories with number prefixed names have Story appended (resulting in -story to be appended in the URL)

For MDX stories:

  • Stories with reserved keyword names (e.g. Delete) have Story appended (resulting in story being appended to the URL)
  • Stories with number prefixed names have _ prepended.

I started to add logic similar to https://github.com/storybookjs/storybook/blob/master/addons/docs/src/mdx/mdx-compiler-plugin.js#L23 to loadStory. However, in Storybook this logic is only run for MDX, so I realized that this would cause problems due to the inconsistency of treatment between CSF & MDX. AFAIK, cypress-storybook has no way to know whether the story is MDX or CSF based, so I got stuck. Pretty frustrating on Storybook's part, to be honest.

@anicholls
Copy link
Contributor Author

As a workaround, you can append Story to the story name in loadStory whenever a reserved name is used (on a case-by-case basis)

@NicholasBoll
Copy link
Owner

I ran into the same thing converting stories from CSF to MDX. Though the stories are still exported like CSF, the MDX document is the one describing the metadata. Storybook also does interesting things via the router that are different whether you enter in the URL manually, or create a link. For example, I cannot link to a category-only via a link, but I can remove the story from the URL manually and Storybook chooses the first story in the nav menu.

I wasn't able to find a solution that knew if the story defined via MDX or CSF to know how to process other than trial. If loadStory fails to load a story and the name contains some of the reserved words, it could retry with Story appended to the end... It is also possible to do a story lookup via a key, so if the key doesn't exist it could try again with -story appended to the end to see if that key exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants