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

Configure svgo to inline styles with >=1 matches #54

Merged
merged 2 commits into from
Nov 15, 2019

Conversation

msand
Copy link
Contributor

@msand msand commented Nov 2, 2019

N.B not tested yet

@kristerkari
Copy link
Owner

Thanks! Sounds good

@msand
Copy link
Contributor Author

msand commented Nov 3, 2019

Interesting, at least in the svgr web interface, those settings seem to make it work

@kristerkari
Copy link
Owner

I tested this with the bones image from the react-native-svg repo, but it does not seem to work, even if I enable SVGO. Let me know how I can help with this.

@msand
Copy link
Contributor Author

msand commented Nov 3, 2019

@kristerkari This seems to be working now

@kristerkari
Copy link
Owner

Thanks! I need to test it again. Btw. is it safe to enable SVGO for everyone? Does it have any known bugs?

@msand
Copy link
Contributor Author

msand commented Nov 3, 2019

I haven't seen any bugs with this configuration, it's possible to give more aggressive options which can be buggy. But this set of options should only make more content compatible with react-native-svg, more specifically, any content with css style elements, having selectors which match more than a single element. This makes react-native-svg-transformer do essentially exactly the same thing as the new SvgCss component in react-native-svg, but at build time instead of runtime.

@msand
Copy link
Contributor Author

msand commented Nov 3, 2019

The plain / default svgo configuration only inlines declarations from css rules where the selector matches exactly one element. Any selector which matches two or more element won't become inlined, and thus will render incorrectly in react-native-svg.

@msand msand changed the title Configure svgo to inline styles with >1 matches Configure svgo to inline styles with >=1 matches Nov 3, 2019
@kristerkari
Copy link
Owner

I haven't seen any bugs with this configuration, it's possible to give more aggressive options which can be buggy. But this set of options should only make more content compatible with react-native-svg

Okay, sounds good! I'm going to include this in the next release.

@kristerkari kristerkari merged commit 9fc5f1b into kristerkari:master Nov 15, 2019
@kristerkari
Copy link
Owner

Thanks! Released in version 0.14.0

@kristerkari
Copy link
Owner

@msand It looks like this ended up being a breaking change after all. I noticed in my app that the default width/height of the SVG images not being applied anymore.

@kristerkari
Copy link
Owner

Looks like that happens because viewBox gets removed.

Adding removeViewBox: false fixes it:

var defaultsvgrConfig = {
  native: true,
  plugins: ["@svgr/plugin-svgo", "@svgr/plugin-jsx"],
  svgoConfig: {
    plugins: [
      {
        inlineStyles: {
          onlyMatchedOnce: false
        }
      },
      {
        removeViewBox: false
      }
    ]
  }
};

Should we add that @msand ?

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

Successfully merging this pull request may close these issues.

2 participants