flobacher / SVGInjector2

Fast, caching, dynamic inline SVG DOM injection library
MIT License
57 stars 8 forks source link

TypeError: i is null / TypeError: Cannot read property 'split' of null #25

Open rotsee opened 6 years ago

rotsee commented 6 years ago

I get an error Uncaught TypeError: Cannot read property 'split' of null in Chrome, and TypeError: i is null [Learn More] in Firefox, given the following code:

<svg data-src="/images/test.svg" id="test"></svg>

document.addEventListener('DOMContentLoaded', function() {
  var elementsToInject = document.querySelectorAll('svg[data-src]');
  console.log(elementsToInject);
  # [svg#test]
  var injector = new SVGInjector();
  console.log(injector);
  # [svg#test]
  # n {}
  # XHR finished loading: GET "http://localhost:3000/images/test.svg".

  injector.inject(elementsToInject);
});

Any ideas how to trobleshoot this?

flobacher commented 6 years ago

Did you try with the latest version.. without investigation, this looks like a bug that has been fixed with 2.1.2. If the error persists, would you mind to share a gist with me, so I can debug this? Thank you!

rotsee commented 6 years ago

I used 2.1.3. Will try and reproduce!

twitwi commented 5 years ago

If anyone falls on this like me, it seems to be due to a wrong handling of the cases where the viewBox attribute is not present on the svg element.

theRealPadster commented 5 years ago

If anyone falls on this like me, it seems to be due to a wrong handling of the cases where the viewBox attribute is not present on the svg element.

Ha, I just had this issue today. Talk about good timing ^^ Thanks!

brianteeman commented 2 years ago

yeah - just hit this problem. if you are using svgomg then it will strip the viewbox