Skip to content
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

InlineSvg does not work on IE11 #10

Open
ElVisPL opened this issue Jan 13, 2020 · 3 comments
Open

InlineSvg does not work on IE11 #10

ElVisPL opened this issue Jan 13, 2020 · 3 comments
Labels
wontfix This will not be worked on

Comments

@ElVisPL
Copy link

ElVisPL commented Jan 13, 2020

It is because IE does not support innerHTML for svg elements

I've fixed it like this on my end using :transform-source. You could use it as a fix.

transformSource(svg) {
      if (!environment.isIE()) {
        return svg
      }

      //InlineSvg component is based on innerHTML
      //and IE11 does not set innerHTML for svg initially
      const serializer = new XMLSerializer()

      const svgContent = Array.prototype.map.call(
        svg.childNodes,
        (child) => serializer.serializeToString(child)
      ).join("")

      svg.innerHTML = svgContent
      return svg
    }
@ElVisPL ElVisPL changed the title InlineSvg does not work for IE11 InlineSvg does not work on IE11 Jan 13, 2020
@shrpne
Copy link
Owner

shrpne commented Jan 13, 2020

Thank you!

innerHTML for SVG can be easily polyfilled, for example, https://github.com/dnozay/innersvg-polyfill.

I do not plan to add polyfill in the repo, because IE11 has low usage, but I think I should add some docs how to support IE11

@lf-jeremy
Copy link

It's also worth noting that IE will not evaluate css styles in SVGs automatically, as noted in other similar projects:

arkon/ng-inline-svg#17

@andypattenden
Copy link

andypattenden commented May 21, 2020

As suggested by @shrpne, using a polyfill allows this to be used in IE11. However, I have come across another issue.

When using this with a webpack configuration which uses url-loader to load the SVG files (in my case Nuxt), and the SVG is below the limit to transform the file into base64, IE will fail to load the file with an Access Denied error.

A fix for this is to use the Webpack Inline Loader configuration to force the use of a different loader or loader config which prevents the base64 conversion, e.g.

<inline-svg
  :src="
    require('!file-loader!../assets/svg/icon.svg')
   "
/>

@shrpne shrpne added the wontfix This will not be worked on label Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants