Skip to content

0.8.0 breaks svg sprite #1153

Closed
Closed
@bogdansoare

Description

@bogdansoare
Contributor

The change in 0.8.0 to use url-loader with limit 10k as a default loader breaks my svg sprite system.

The svg sprite system works like this: I put all my svgs in one folder, run svg-sprite to generate svg sprite (which is below 10k), then I have a custom Icon component in which I import the svg sprite and load the apropriate icon using fragment identifiers

Icon Component:

import React, { PropTypes } from 'react'
import svgSprite from '../img/symbol/sprite.svg'

function Icon({ name }) {
  return (
    <svg>
      <use xlinkHref={`${svgSprite}#${name}`} />
    </svg>
  )
}

Any idea how to fix this besides just adding more svgs to the sprite until it is bigger than 10k?

Activity

gaearon

gaearon commented on Dec 4, 2016

@gaearon
Contributor

Do fragments break with base64 URLs?

gaearon

gaearon commented on Dec 4, 2016

@gaearon
Contributor

Or do you rather mean that it's unfortunate sprites get duplicated?

If this is the case I think we should disable inlining for SVG. After all the user could've put it directly into components if they wanted to inline it.

bogdansoare

bogdansoare commented on Dec 4, 2016

@bogdansoare
ContributorAuthor

Fragments break with base64.
Also like you said it's unfortunate that we can't leverage caching and that we inline the whole sprite everywhere an icon is used.

Disabling inlining for SVG would solve the issue.
I'm going to research a bit svg sprite systems and see if there are other reasonable possibilities besides fragment identifiers.

gaearon

gaearon commented on Dec 5, 2016

@gaearon
Contributor

Would you like to make a PR for a special case for SVG?

bogdansoare

bogdansoare commented on Dec 5, 2016

@bogdansoare
ContributorAuthor

Sure, I'll be glad to make a PR

added this to the 0.8.1 milestone on Dec 5, 2016
gaearon

gaearon commented on Dec 6, 2016

@gaearon
Contributor

Fixed by #1180.

mzedeler

mzedeler commented on Jun 13, 2018

@mzedeler

What is required to make inlining of svg images below 10k work (again)?

tilman

tilman commented on Jul 10, 2018

@tilman

Is there a Option to re-activate base64 import for SVGs? I'm using SVGs in my CSS and i don't like the workflow of manually transforming it to base64 first.

3 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mzedeler@gaearon@bogdansoare@tilman

        Issue actions

          0.8.0 breaks svg sprite · Issue #1153 · facebook/create-react-app