Svg not render <path> when added css all:revert

Viewed 155

I'm using 3rd party UI library, which is includes such rule:

* {all: revert;}

then I add svg, but it's not renders, since width and height of <path> is equal to 0. I have no ability to remove all: revert; in code (only override).

Here is demo: https://codesandbox.io/s/suspicious-cori-4pgfh

What style need to add to <path> to make it visible?

UPD: Here code snippet

body {
  font-family: sans-serif;
}

/* this cannot be removed  */
body * {
  all: revert; /* this added by 3-rd party library */
}

.svg-wrapper * {
  display: block;
  width: 100px;
  height: 100px;
}

.svg-wrapper path {
  display: block;
  width: 100px;
  height: 100px;
}
<!DOCTYPE html>
<html>
  <head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
  </head>

  <body>
    <div class="svg-wrapper">
      <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
        <path
          d="M 10,30
                         A 20,20 0,0,1 50,30
                         A 20,20 0,0,1 90,30
                         Q 90,60 50,90
                         Q 10,60 10,30 z"
        />
      </svg>
    </div>

  </body>
</html>

UPD: When override with body * { all: initial; } - doesn't work

2 Answers

It's the d data (which is also a CSS property now) that gets reset by all: revert;, and because CSS properties always override SVG attributes, your <path> doesn't contain a shape anymore.

The only fix I could find is to run a script that copies the d SVG attribute into the d CSS property on all <path> elments:

document.querySelectorAll('path').forEach(path => {
  const data = path.getAttribute('d').replace(/\s+/g, ' '),
        cssData = `path("${data}")`;
  path.style.d = cssData;
});

document.querySelectorAll('path').forEach(path => {
  const data = path.getAttribute('d').replace(/\s+/g, ' '),
        cssData = `path("${data}")`;
  path.style.d = cssData;
});
body {
  font-family: sans-serif;
}

/* this cannot be removed  */
body * {
  all: revert; /* this added by 3-rd party library */
}

.svg-wrapper * {
  display: block;
  width: 100px;
  height: 100px;
}

.svg-wrapper path {
  display: block;
  width: 100px;
  height: 100px;
}
<!DOCTYPE html>
<html>
  <head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
  </head>

  <body>
    <div class="svg-wrapper">
      <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
        <path
          d="M 10,30
                         A 20,20 0,0,1 50,30
                         A 20,20 0,0,1 90,30
                         Q 90,60 50,90
                         Q 10,60 10,30 z"
        />
      </svg>
    </div>

  </body>
</html>

*:not(path) {all: revert;} will apply the revert but keep the SVG path intact

Related