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

Svelte Example Components injecting global CSS #19409

Closed
Amerlander opened this issue Oct 9, 2022 · 4 comments · Fixed by #22162
Closed

Svelte Example Components injecting global CSS #19409

Amerlander opened this issue Oct 9, 2022 · 4 comments · Fixed by #22162

Comments

@Amerlander
Copy link
Contributor

Amerlander commented Oct 9, 2022

Describe the bug
The example components (Button, Header, Page) are adding the CSS files trough import './header.css';.
The CSS is then Globally available and not scoped to the Component.

import Button from './Button.svelte';

The Behavior of adding CSS through an Import is resulting in global CSS is not the Bug. Usual, most Svelte Components would not import CSS like that, and therefore I think having a Component as a sample which introduces a bad pattern and leads to side effects should be avoided.

To Reproduce
Every new installation of Storybook ads this behavior.

Additional context
There are two ways so solve that (sveltejs/svelte#7125):

  • Create a container element, add css to that and import the external css file through a precompiler like scss
  • Do not import the css file, but write the CSS directly inside the component.

I think adding css into the components will be cleaner, but it will also mean duplicating the css code for svelte.

@Amerlander
Copy link
Contributor Author

Example: Here is an Icon component, that has an unstyled SVG. But there is still some css applied, which comes from the header-css:
image

Also, I have a Button component, which has an Icon.
This is how it should look like and how it looks on my actual site:
image

And this is how the component looks like in storybook after a fresh installation of storybook:
image

I think storybook should not come with that behavior by default. So a novice User should not have to remove three components after installation to avoid css issues.

@shilman
Copy link
Member

shilman commented May 9, 2023

ZOMG!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.1.0-alpha.14 containing PR #22162 that references this issue. Upgrade today to the @future NPM tag to try it out!

npx sb@next upgrade --tag future

@shilman
Copy link
Member

shilman commented May 9, 2023

Jiminy cricket!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.10 containing PR #22162 that references this issue. Upgrade today to the @latest NPM tag to try it out!

npx sb@latest upgrade

@yannbf
Copy link
Member

yannbf commented May 10, 2023

Thank you so much @Amerlander !!

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

Successfully merging a pull request may close this issue.

3 participants