question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SVGs load inconsistently in Docs mode for HTML stories when using file-loader

See original GitHub issue

Describe the bug When authoring HTML stories and viewing them in Docs mode, when multiple stories contain an <svg><use href="..."></svg> only some of them (non-deterministically) render.

To Reproduce Steps to reproduce the behavior:

  1. Using file-loader, author a number of story previews in Docs mode that use <svg> with a <use href="..."> reference
  2. Run and open the Storybook
  3. Navigate to Docs tab
  4. Observe not all icons load

Expected behavior Any correctly-specified SVGs render on the page

Screenshots How the HTML stories render (sometimes more or different icons load):

Screenshot 2020-01-01 21 48 56

How the React stories render, which is the expected behavior:

Screenshot 2020-01-01 21 49 33

Code snippets The HTML stories load the SVGs like so:

const icons = require('@/assets/icons.svg');

<Preview>
  <Story name="Base alert">{`
    <svg role="img" aria-hidden="true">
      <use href="${icons}#status-base" />
    </svg>
  `</Story>
</Preview>

<Preview>
  <Story name="Info alert">{`
    <svg role="img" aria-hidden="true">
      <use href="${icons}#status-info" />
    </svg>
  `</Story>
</Preview>

System:

Environment info
  System:
    OS: macOS Mojave 10.14.5
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Node: 12.4.0 - ~/.nvm/versions/node/v12.4.0/bin/node
    npm: 6.13.4 - ~/.nvm/versions/node/v12.4.0/bin/npm
  Browsers:
    Chrome: 79.0.3945.88
    Firefox: 71.0
    Safari: 12.1.1
  npmPackages:
    @storybook/addon-a11y: ^5.3.0-rc.6 => 5.3.0-rc.6
    @storybook/addon-docs: ^5.3.0-rc.6 => 5.3.0-rc.6
    @storybook/addon-knobs: ^5.3.0-rc.6 => 5.3.0-rc.6
    @storybook/addon-storysource: ^5.3.0-rc.6 => 5.3.0-rc.6
    @storybook/html: ^5.3.0-rc.6 => 5.3.0-rc.6
    @storybook/react: ^5.3.0-rc.6 => 5.3.0-rc.6
    @storybook/source-loader: ^5.3.0-rc.6 => 5.3.0-rc.6
    @storybook/vue: ^5.3.0-rc.6 => 5.3.0-rc.6

Additional context We disable Storybook’s default SVG loader and use file-loader instead. I might suspect this is related to the issue, except that the SVGs do in fact load, though sporadically. Does not exhibit issues in the React or Vue storybooks.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
shilmancommented, Jan 24, 2020

Sorry, missed this the first time around. I think the key difference might be that @storybook/html is rendering those stories in iframes, which can be problematic, whereas React is rendering them inline.

Vue also renders in iframes by default, but can be configured to run inline. But perhaps there are subtle rendering differences that cause it to be more reliable than @storybook/html.

There’s also @storybook/web-components which can be configured to run inline and should support a superset of HTML. We could also probably use the same method to allow @storybook/html run inline. cc @daKmoR

0reactions
daneahcommented, Jul 20, 2020

Sorry for the lack of follow-up here—we rapidly switched to web components only, so haven’t really been digging into HTML Storybook at all, of late.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack - file-loader not working (unable to load svg file in ...
i got the hash from the command line imgs/webpackImage.bad207360b17088a7d31eb8b64674910.jpeg and pasted into the src of the image in the html ...
Read more >
svg-loader: A Different Way to Work With External SVG
Simply put, it fetches the SVG files via XHR and loads them as inline ... (Open in incognito mode as the files are...
Read more >
@docusaurus/plugin-debug | Yarn - Package Manager
We are working hard on Docusaurus v2. If you are new to Docusaurus, try using the new version instead of v1. See the...
Read more >
Untitled
Monsters sightings 2013, Section 30 of nirc of 1997, Unreal engine tutorial for beginners, Logotyp penna, Logo with 2 red hearts, Abi beni...
Read more >
Is it a good practice to use an SVG as a logo? - Quora
There is pretty much only one way to go with icons, logos and illustrations on the ... This guide aims to give a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found