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

[Bug] Error when Story name is same as component import specifier #250

Open
xeho91 opened this issue Dec 20, 2024 · 2 comments
Open

[Bug] Error when Story name is same as component import specifier #250

xeho91 opened this issue Dec 20, 2024 · 2 comments
Assignees
Labels
next Related to the next version

Comments

@xeho91
Copy link
Collaborator

xeho91 commented Dec 20, 2024

Describe the bug

Discord thread

What is happening:
In the appendix of compiled out of Svelte component, we're creating export variable declarations whose names are based on the name prop in each <Story>.
We didn't cover the case when Story name could re-declare the import specifier of the component.

Steps to reproduce the behavior

Define a <Story> with name prop having the same as component import declaration.

@xeho91 xeho91 added the next Related to the next version label Dec 20, 2024
@xeho91 xeho91 self-assigned this Dec 20, 2024
@JReinhold
Copy link
Collaborator

JReinhold commented Dec 20, 2024

Probably a duplicate of #167

This is not just a problem with imported component names, it will happen with any variable name declared in the module scope that collides with a story name.

A workaround is to use the exportName prop on Story to manually fix the collision.

https://github.com/storybookjs/addon-svelte-csf/tree/next?tab=readme-ov-file#custom-export-name

It's a tricky issue to solve, because the name/exportName of the story is used in MDX docs, where you import them by that name, so we can't just attach a hash to the variable name, as that would make it impossible to import.

@xeho91
Copy link
Collaborator Author

xeho91 commented Dec 22, 2024

I have one idea in my mind. I'm not sure if this solves the problem.

Currently in the appendix we create named exports (variables).
What if we could use exports list? Example:

const __SomePrefix__Primary = __stories["Primary"];
const __SomePrefix__Secondary = __stories["Secondary"];

export {
  __SomePrefix_Primary as Primary,
  __SomePrefix_Secondary as Secondary,
}

In the case of having <Story> prop name same as component import specifier, it would look like this:

import Button from "./Button.svelte";

const __SomePrefix__Button = __stories["Button"];

export {
  __SomePrefix__Button as Button,
}

Concerns:

  1. This possibly would affect your recent work on the issue with source maps (related to portable stories),
  2. I'm unsure if Storybook internal parser(?) covers this case.

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

No branches or pull requests

2 participants