storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
84.68k stars 9.32k forks source link

[Bug]: Svg Icon can not load If use react-svg and storybook-addon-mock #26314

Open linhhuynhcamis opened 8 months ago

linhhuynhcamis commented 8 months ago

Describe the bug

I use react-svg to load svg icon from public folder. When I run project, the svg icon will be showed normally. But when I run storybook. Svg Icon cannot load on storybook. I will check two cases:

To Reproduce

No response

System

No response

Additional context

No response

imf commented 8 months ago

I have this problem too!

hwangar commented 1 month ago

Hey guys, I've been struggling on this one as well and these are my findings: TLDR; SADLY, it won't work...

from https://github.com/berniegp/mock-xmlhttprequest/blob/main/src/MockXhr.ts comments you can see:

Partial support:

which are the ones used by react-svg... so it won't get the expected xml document at all :(, not but a limitation in storybook-rest-mock, but in it's inner dep implementation, same as other's use cases using these unsupported responseXml

My 2 cents: I decided to mock library to drop support of XMLHttpRequest mocking at all and stay with just fetch mocking as it was what I needed and the XMLHttpRequest alternative is "partially supported"