-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: gracefully handle stories named the same as standard javascript keywords #41
Conversation
@JReinhold I hope its okay to ping you here. Is it currently possible to have stories with a id that conflicts with a standard javascript keyword? For example, is it possible to overwrite the story id with something like this? export const defaultStory = () => ...
defaultStory.storyName = 'Default'
defaultStory.storyId = 'Default' I couldn't find anything in this direction, so I went with adding a prefix |
Codecov Report
@@ Coverage Diff @@
## main #41 +/- ##
==========================================
+ Coverage 96.42% 96.47% +0.05%
==========================================
Files 3 3
Lines 280 284 +4
Branches 45 45
==========================================
+ Hits 270 274 +4
Misses 10 10
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I don't think there's anything stopping you from using reserved keywords as IDs, I just think that what you're running into here is a limit of the language. I think this would help if you generated CSF3 stories instead of CSF2. So export const defaultStory = () => ...
defaultStory.storyName = 'Default'
defaultStory.storyId = 'Default' would instead be export const Default = {
id: 'default',
name: 'default',
render: () => ...
} |
Thanks, migrating to csf3 is a good idea, I wanted to do that anyway. But I couldn't find anything about the |
Sorry, I was mixing things up. https://storybook.js.org/docs/7.0/vue/configure/sidebar-and-urls#permalink-to-stories |
Thanks for the link, but it's still not clear to me how I would allow users to choose export const default: Story = {}; clearly doesn't work. Is this just a limitation one has to accept, or is there a nice workaround? |
The "nice workaround" is to PascalCase all the story exports, so they don't conflict with JS keywords. In general we actually always recommend PascalCase for story exports, probably for stuff like this. This works: const meta = {
...
} satisfies Meta<Button>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
};
export const Class: Story = {
};
export const If: Story = {
}; |
Thanks a lot @JReinhold. Using pascalcase worked really well! |
Having a story with the name 'Default' leads to the error:
This is fixed by changing the story export to be capitalized. Fixes #48.