-
-
Notifications
You must be signed in to change notification settings - Fork 424
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
Replace rehype with svg-parser #321
Conversation
https://npm.anvaka.com/#/view/2d/rehype https://packagephobia.now.sh/result?p=rehype https://packagephobia.now.sh/result?p=svg-parser https://npm.anvaka.com/#/view/2d/svg-parser Did not notice any changes in speed. Though startup time is probably better.
This pull request is automatically deployed with Now. |
Another point with reasonml can be solved with templating a simple string instead of babel stuff. I want to send a PR too. |
Codecov Report
@@ Coverage Diff @@
## master #321 +/- ##
=========================================
- Coverage 86.66% 86.3% -0.37%
=========================================
Files 30 27 -3
Lines 480 460 -20
Branches 134 129 -5
=========================================
- Hits 416 397 -19
+ Misses 53 52 -1
Partials 11 11
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #321 +/- ##
=========================================
- Coverage 86.66% 86.3% -0.37%
=========================================
Files 30 27 -3
Lines 480 460 -20
Branches 134 129 -5
=========================================
- Hits 416 397 -19
+ Misses 53 52 -1
Partials 11 11
Continue to review full report at Codecov.
|
Hello @TrySound, the whole point of SVGR is to be robust, I think moving to a un-maintained SVG parser is not good idea. Especially if the only gain is 600ko. Also they are chance that In fact I could be OK but I am sure we will have issue with some weird SVG not parsed correctly. |
svg-parser is not really unmaintained. It's complete project and no bugs are found yet :) Rich released my PR in a couple of hours 3 days ago. Rehype can be so complex because of parsing html syntax which is very loose. SVG is strict XML, no need to cover all html use cases. I ran new code on 150 icons in my project and they compiled without problems. |
OK Thanks, so maybe we should consider it. |
@neoziro Rich is ok to migrate to hast so we do not need to make changes in hast-util-to-babel-ast. |
Codecov Report
@@ Coverage Diff @@
## master #321 +/- ##
========================================
- Coverage 86.66% 85% -1.67%
========================================
Files 30 30
Lines 480 480
Branches 134 134
========================================
- Hits 416 408 -8
- Misses 53 60 +7
- Partials 11 12 +1
Continue to review full report at Codecov.
|
@neoziro I reverted all changes in hast-util-to-babel-ast so we don't have to rename the plugin :) |
Hi folks! I don’t want to pick a fight, if you want to switch to something that’s fine, but I would be cautious about it! rehype-parse uses parse5, which is often already in node_modules anyway (through jsdom). unified and vfile are typically in node modules as well (such as through prettier).
It may be complete, or it could be that it isn’t used a lot (2.5k downloads a week) compared to rehype-parse (1.2m a week), so bugs aren't found. Oh that’s cool! Be careful though, hast properties aren’t more complex than settings attribute names and values on an object: https://github.com/syntax-tree/hast#properties One reason to switch to something else from rehype-parse is that rehype-parse is for HTML, and it supports SVG in HTML. But it’s not made just for SVG. |
Hi! Thanks for answer. Not really true about prettier. It bundles all dependencies. Properties in svg-parser are either string or numbers. There should not be problems. |
Ah, interesting! Well prettier was one example, but in that case the usage is even higher than I thought ;)
What I mean is that the casing of hast properties is different, and that values are not always strings or numbers. It may work, but it’s not conforming hast, so it also may not work. |
Hi, The new release gives me an output that react-native-svg won't understand. It worked in friday: Original SVG:
This works (manual rework) import React from 'react';
import Svg, { G, Path, Circle, SvgProps } from 'react-native-svg';
const SVGMoon = (props: SvgProps) => (
<Svg width="1em" height="1em" viewBox="0 0 30 30" {...props}>
<Path
d="M24.749132,24.0262157 C24.3556455,23.9469222 23.962159,23.8501007 23.5820565,23.7382551 C19.6355926,22.5805699 16.584065,19.8286681 15.2099853,16.1878443 C13.8359056,12.5470206 14.363231,8.6132282 16.6581225,5.39391201 C16.8802951,5.08258069 17.1203129,4.77709203 17.3728224,4.48495808 C17.450449,4.39481389 17.4656174,4.27128296 17.4120818,4.16778407 C17.357654,4.06428518 17.2452293,3.99918104 17.1220975,4.00001571 C15.7890617,4.01670908 14.4703021,4.23706155 13.2006168,4.65689978 C6.80936175,6.76777627 3.4455433,13.349137 5.70206766,19.327867 C7.95859203,25.3074318 14.9949507,28.4541318 21.3862058,26.3432553 C22.6558911,25.9242517 23.8301046,25.3207865 24.8785096,24.5503875 C24.9757659,24.4794407 25.0194866,24.3625871 24.9918266,24.2499068 C24.9641665,24.1372266 24.869587,24.0504211 24.749132,24.0262157 Z"
stroke="currentColor"
strokeWidth={2.1}
fill="none"
fillRule="evenodd"
/>
</Svg>
);
export default SVGMoon; This is direct output from new release, and won't work due to bad path: import React from 'react'
import Svg, { Path } from 'react-native-svg'
/* SVGR has dropped some elements not supported by react-native-svg: title */
const SvgComponent = props => (
<Svg width="1em" height="1em" viewBox="0 0 30 30" {...props}>
<Path
d="M24.75 24.026c-.394-.08-.788-.176-1.168-.288-3.946-1.157-6.998-3.91-8.372-7.55-1.374-3.641-.847-7.575 1.448-10.794.222-.311.462-.617.715-.909a.283.283 0 00.04-.317.323.323 0 00-.29-.168 12.99 12.99 0 00-3.922.657c-6.392 2.11-9.755 8.692-7.499 14.67 2.257 5.98 9.293 9.127 15.684 7.016a12.495 12.495 0 003.493-1.793.286.286 0 00.113-.3.308.308 0 00-.243-.224z"
stroke="#20222B"
strokeWidth={2.1}
fill="none"
fillRule="evenodd"
/>
</Svg>
)
export default SvgComponent Edit: I don't know if this is due to the new parser or not. Maybe it's just SVGO need to be removed for RN as without it, it works. Don't remember having unchecked SVGO last week so maybe a default setting has changed? |
Try before the latest version, if it works it is the parser and I will probably revert it if we have other issues. |
I got the same with 4.3.1. Looks like svgo issue. |
Context:
https://npm.anvaka.com/#/view/2d/rehype
https://packagephobia.now.sh/result?p=rehype
https://packagephobia.now.sh/result?p=svg-parser
https://npm.anvaka.com/#/view/2d/svg-parser
Did not notice any changes in speed. Though startup time is probably
better.