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.

SVG files imported as React components should not end up in build directory

See original GitHub issue

Intro

SVG files can be imported as React component, and thus inlined into the bundle, using the following syntax:

import { ReactComponent as MySvg } from '../../assets/icons/my-svg.svg'

Actual behaviour

Although inlined, the original SVG files will still be processed (by Webpack?) and end up

  • in the build/static/media folder
  • in the asset-manifest.json file

Overall, this isn’t critical - it only means that unused files end up in the build folder. Nevertheless, it’s a very confusing behaviour, developers might assume those files are being used or even that SVGs imported the way described above are not being inlined.

Expected behaviour

The expected behaviour is that inlined resources do not end up in the build folder, resulting in a smaller and clean build folder.

Related

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:7

github_iconTop GitHub Comments

5reactions
Soberiacommented, Nov 28, 2020

Overall, this isn’t critical

It’s critical when using Service Worker. Because SVG files also included in self.__WB_MANIFEST value which contains URLs to precache. That means browsers will send requests to precache all these SVG files which don’t need at all

0reactions
dominique-muellercommented, Oct 5, 2020

Not stale.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing SVG as React component not working with Next.js
I end up with this error: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite ...
Read more >
How to use SVGs in React | Sanity.io guide
Use it as a regular image; Import it as a component via bundler magic (SVGR); Include it directly as JSX. Let's quickly go...
Read more >
React SVG: How to use SVGs best in React - CopyCat Blog
In this article, we'll look at react SVG - importing SVG into react, how to convert SVG to components, and much more.
Read more >
How to use SVGs in React - LogRocket Blog
Let's start by taking a look at some of SVG's advantages over other ... Also, if you use inline SVG in your code,...
Read more >
Optimizing Performance - React
This will create a production build of your app in the build/ folder of your project. ... Remember that only React files ending...
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