Open anicholls opened 3 years ago
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)
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.
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:
Delete
) are not touched (URL is unaffected)Story
appended (resulting in-story
to be appended in the URL)For MDX stories:
Delete
) haveStory
appended (resulting instory
being appended to the URL)_
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.