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

Can generate React components with string style attribute #7

Closed
twm opened this issue Oct 16, 2017 · 5 comments
Closed

Can generate React components with string style attribute #7

twm opened this issue Oct 16, 2017 · 5 comments

Comments

@twm
Copy link
Contributor

twm commented Oct 16, 2017

If SVGO doesn't manage to remove all of the CSS in the style attribute, svgr will generate a React component with a string style prop, which is invalid. For example, when I run 0.4.0 against this Inkscape SVG this is what I get:

import React from "react";

const List = props => (
  <svg
    xmlnsXlink="http://www.w3.org/1999/xlink"
    width={48}
    height={48}
    {...props}
  >
    <g transform="translate(0 -1004.362)">
      <g id="a" color="#000" fill="#a3a3a3" strokeWidth={8}>
        <rect
          style="marker:none"
          width={4}
          height={4}
          x={4}
          y="1010.362"
          rx=".2"
          ry=".2"
          overflow="visible"
        />
        <rect
          ry=".2"
          rx=".2"
          y="1010.362"
          x={12}
          height={4}
          width={32}
          style="marker:none"
          overflow="visible"
        />
      </g>
      <use xlinkHref="#a" />
      <use xlinkHref="#a" transform="translate(0 8)" />
      <use xlinkHref="#a" transform="translate(0 16)" />
      <use xlinkHref="#a" transform="translate(0 24)" />
      <use xlinkHref="#a" transform="translate(0 32)" />
    </g>
  </svg>
);

export default List;

This component fails to render because of the style="marker:none" props.

@gregberge
Copy link
Owner

Thanks for reporting it! We should easily handle it by creating a h2x plugin.

@twm
Copy link
Contributor Author

twm commented Oct 16, 2017

Hmm, maybe this is due to a specific svgo version? If I run the SVG through svgomg I get:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48">
  <g transform="translate(0 -1004.362)">
    <g id="a" color="#000" fill="#a3a3a3" stroke-width="8">
      <rect width="4" height="4" x="4" y="1010.362" rx=".2" ry=".2" overflow="visible"/>
      <rect ry=".2" rx=".2" y="1010.362" x="12" height="4" width="32" overflow="visible"/>
    </g>
    <use xlink:href="#a"/>
    <use xlink:href="#a" transform="translate(0 8)"/>
    <use xlink:href="#a" transform="translate(0 16)"/>
    <use xlink:href="#a" transform="translate(0 24)"/>
    <use xlink:href="#a" transform="translate(0 32)"/>
  </g>
</svg>

The relevant toggle is "Remove unknowns & defaults". svgomg seems to be using [email protected] while I have [email protected] locally.

I can't find any reference information for this marker CSS property on MDN, so maybe it's just garbage Inkscape inserted?

@twm
Copy link
Contributor Author

twm commented Oct 16, 2017

It looks like https://github.com/svg/svgo/releases/tag/v0.6.4 changed behavior with respect to unknown CSS properties (which were previously translated into invalid element attributes, which were dropped).

@twm
Copy link
Contributor Author

twm commented Oct 16, 2017

For anyone else stumbling across this, it looks like I can stop Inkscape from adding this invalid marker:none CSS property by checking some boxes in the preferences:

inkscape-strip-attrs

gregberge added a commit to smooth-code/h2x that referenced this issue Oct 30, 2017
gregberge added a commit that referenced this issue Oct 30, 2017
gregberge added a commit that referenced this issue Oct 30, 2017
@gregberge
Copy link
Owner

Fixed in v0.5.0

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

No branches or pull requests

2 participants