Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Embeded SVG icons cause rendering issues on reponse other than 200 #26

Open
WengerK opened this issue Mar 13, 2018 · 1 comment
Open
Labels

Comments

@WengerK
Copy link
Member

WengerK commented Mar 13, 2018

Motivation/Probleme

When no SVG icons are generated, the page embed the 404 page into the current page.

For now, we have to add the following code to works with SVGIcon

<!-- Toolbox svg icons -->
<script type="text/javascript">
window.svgPath = "/{{ directory }}/build/icons/icons.svg";
</script> 

The problem is that the code will fetch the given path & it will append the results to the page, even with a non 2xx response is given .... Then it will append a 404 embed into the current page !

Resolutions

Check the response code before append it into the page.

@WengerK WengerK added the bug label Mar 13, 2018
@Yago
Copy link
Member

Yago commented Mar 13, 2018

You can manually add a test into your assets/svg/svg-icons.js like :

const svgIcons = () => {
  const ajax = new XMLHttpRequest();
  const svgPath = window.svgPath || 'icons/icons.svg';
  ajax.open('GET', svgPath, true);
  ajax.send();
  ajax.onload = function (e) {
    if (200 >= ajax.status < 300) { // ← here
      var div = document.createElement('div');
      div.innerHTML = ajax.responseText;
      document.body.insertBefore(div, document.body.childNodes[0]);
    } // ← end here
  };
};

export default svgIcons;

We must add that to the generator too 😉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants