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]: [7.0.0-beta.17]: Storybook doesn't display SVG icons #20465
Comments
@valentinpalkovic assuming this is either a windows issue or a nextjs issue (or both) -- either way, ball's in your court! 😂 |
I also experienced this issue. At first I thought that the Storybook beta was broken, but it is actually a simpler issue - the NextJS framework changes all image imports. Normally, if you would do this:
You would get a string, which is the location where the svg is hosted. However, if you use the NextJS framework plugin from Storybook, the same code would give a different output. It would output an object with a This means that the default Storybook examples break, because While this is not a bug in Storybook, or a bug in the NextJS plugin, it does give a bad first impression of Storybook. The recommended way of starting a NextJS+Storybook project shows broken images by default. Maybe the NextJS plugin should replace the demo content with content that is compatible with the plugin, to not scare off users that are trying Storybook out for the first time. |
It seems to me there is a problem with Storybook's webpack config. After updating the storybook webpack config with the example from the docs (Storybook for Next.js) and simply replacing |
@bartlangelaan You‘re right. The documentation and the example stories have to be adjusted! I will find some time next week to update the examples! Thank you so much for your investigations! |
Yee-haw!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-beta.44 containing PR #20798 that references this issue. Upgrade today to the
|
For those who are struggling with // Add SVGR Loader so Storybook can read .svg files properly
// ---------
const assetRule = config.module.rules.find(({ test }) => test.test('.svg'))
const assetLoader = {
loader: assetRule.loader,
options: assetRule.options || assetRule.query,
}
// Merge our rule with existing assetLoader rules
config.module.rules.unshift({
test: /\.svg$/,
use: ['@svgr/webpack', assetLoader],
})
// --------- I tried using the |
When using Next.js, using forEach instead of find works fine. config?.module?.rules?.forEach(rule => {
if (!rule || typeof rule !== 'object') return;
if (rule.test instanceof RegExp && rule.test.test('.svg')) {
rule.exclude = /\.svg$/;
}
}); |
@Karibash or @carlosrsabreu where would this code be added? thanks! |
In
|
yes, that worked! Thanks a bunch! |
Describe the bug
In the latest version of the Storybook (7.0.0-beta.17) SVG icons in the Introduction.mdx don't display correctly.
Here's a screenshot of what it looks like:
To Reproduce
System
Additional context
No response
The text was updated successfully, but these errors were encountered: