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.

LinearGradient crash with xlink:href

See original GitHub issue

xlink:href are not supported, the use of it causes a crash. linearGradient that use xlink:href have no children elements which causes a call on undefined.

Example

<svg id="b809eb86-ec6b-4213-aa3e-83f4128e49a5" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink" width="1082" height="725" viewBox="0 0 1082 725">
    <defs>
        <linearGradient id="b7709055-0dd4-48d6-ac10-5a758f15d1a1" x1="443.56" y1="792.13" x2="443.56" y2="251.5"
                        gradientUnits="userSpaceOnUse">
            <stop offset="0" stop-color="gray" stop-opacity="0.25"/>
            <stop offset="0.54" stop-color="gray" stop-opacity="0.12"/>
            <stop offset="1" stop-color="gray" stop-opacity="0.1"/>
        </linearGradient>
        <linearGradient id="f59ba046-7ebe-407e-be3d-c62856fc1078" x1="712" y1="788.54" x2="712" y2="248.5"
                        xlink:href="#b7709055-0dd4-48d6-ac10-5a758f15d1a1">
        </linearGradient>
    </defs>
</svg>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
MillerGregorcommented, Aug 2, 2019

in case anyone else runs into this…

IF you have access to the source AND you’re using Illustrator

save as settings: SVG 1.1 type: SVG subsetting: none Image location: (whatever) css properties: Presentation Attributes

I then process via gulp

gulpfile.js:

var gulp = require('gulp');
var svgmin = require('gulp-svgmin');
var replace = require('gulp-replace');

gulp.task('svg', function() {
  return gulp
    .src('./svg/in/*.svg')
    .pipe(
      svgmin({
        plugins: [
          { removeXMLNS: true },
          {
            inlineStyles: { onlyMatchedOnce: false, removeMatchedSelectors: false }
          },
          { convertStyleToAttrs: true }
        ]
      })
    )
    .pipe(
      svgmin({
        plugins: [{ removeStyleElement: true }, { removeEmptyContainers: true }]
      })
    )
    .pipe(
      svgmin({
        plugins: [
          { removeEmptyContainers: true },
          {
            removeAttrs: {
              attrs: '(class|data-name)'
            }
          },
          {
            convertShapeToPath: {
              convertArcs: true
            }
          }
        ]
      })
    )
    .pipe(
      svgmin({
        plugins: [
          {
            mergePaths: {
              collapseRepeated: true,
              leadingZero: true,
              negativeExtraSpace: true
            }
          }
        ]
      })
    )
    .pipe(
      replace(/xlink:href=/g, (match, p1, offset, string) => {
        return `href=`;
      })
    )
    .pipe(
      replace(/stop-color=/g, (match, p1, offset, string) => {
        return `stopColor=`;
      })
    )
    .pipe(
      replace(/clip-path=/g, (match, p1, offset, string) => {
        return `clipPath=`;
      })
    )
    .pipe(
      replace(/stroke-linecap=/g, (match, p1, offset, string) => {
        return `strokeLinecap=`;
      })
    )
    .pipe(
      replace(/stroke-linejoin=/g, (match, p1, offset, string) => {
        return `strokeLinejoin=`;
      })
    )
    .pipe(
      replace(/stroke-width=/g, (match, p1, offset, string) => {
        return `strokeWidth=`;
      })
    )
    .pipe(
      replace(/stroke-miterlimit=/g, (match, p1, offset, string) => {
        return `strokeMiterlimit=`;
      })
    )
    .pipe(
      replace(/="(-?[0-9]*\.[0-9]*)"/g, (match, p1, offset, string) => {
        return `={${p1}}`;
      })
    )
    .pipe(
      replace(/<(\w)/g, (match, p1, offset, string) => {
        return '<Svg.' + p1.toUpperCase();
      })
    )
    .pipe(
      replace(/<\/(\w)/g, (match, p1, offset, string) => {
        return '</Svg.' + p1.toUpperCase();
      })
    )
    .pipe(gulp.dest('./svg/out'));
});
0reactions
stale[bot]commented, Feb 15, 2020

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

LinearGradient crash with xlink:href · Issue #919 - GitHub
linearGradient that use xlink:href have no children elements which causes a call on undefined. Example. <svg id="b809eb86-ec6b-4213-aa3e- ...
Read more >
LinearGradient with href to another linearGradient not working ...
I have this code showing a linearGradient using an href to ... Use xlink:href and not href ... The [collapse] tag is being...
Read more >
305021 - crash in [@ nsSVGGradientFrame::checkURITarget] if ...
It happens with a radialGradient that has an attribute like xlink:href="url(#g2)" - it doesn't have to reference itself. If the reference is of...
Read more >
Bug #1318657 “Drag&Drop imports wrongly gradients (leads to cras ...
Based on tests with archived builds, the crash in Fill&Stroke seems to be ... dropping 4100, so xlink:href to a nonexistent lineargradient, and...
Read more >
580809 - Changing xlink:href attribute on <use> is flaky with ...
This is an interesting bug and has something to do with cache-control: max-age=0. I've created a simpler testcase that exhibits this bug and...
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