Open revelt opened 2 years ago
Hello @revelt, same as the other issue, I am OK with it!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
It's quick, no-brainer improvement to prevent some edge cases. Who's keen to debug different SVG specs anyway?
I may pick this up as a part of SVGO, but just want to note an edge case that doesn't make this that simple. An SVG may have a <style>
tag in it, which may include selectors that depend on the order of elements.
Consider the following:
<svg viewBox="0 0 256 172" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid">
<style>
svg path:nth-child(2) {
color: red;
}
</style>
<path d="M112.973416,9.2496789 C105.800602,-3.0832263 87.8689954,-3.0832263 80.6961815,9.2496789 L2.52446046,143.659628 C-4.64826776,155.992961 4.3176211,171.408985 18.6631204,171.408985 L79.688321,171.408985 C73.5584906,166.051862 71.2883417,156.784087 75.9271555,148.832569 L135.130926,47.3479175 L112.973416,9.2496789 Z" fill="currentcolor"/>
<title>Title</title>
</svg>
If <title>
were to be moved to the top without modifying the selector, the styles would break. This would definitely always be safe when no JavaScript or script
tag is present, though.
π Feature Proposal
For backwards compatibility with SVG 1.1 (https://developer.mozilla.org/en-US/docs/Web/SVG/Element/title), we must put
<title>
as the first child, no matter the order it originally comes in.Motivation
It would be nice if
svgr
automatically corrected the position of<title>
element, pushing it forward, to be the first child element.Example
svgr
currently doesn't care about the<title>
tag position. Quick adapted placeholder snippet from the GUI web page app:Above, the
<title>
comes in at a wrong position andsvgr
should be able to automatically fix it.Pitch
Why does this feature belong in the SVGR ecosystem? It's quick, no-brainer improvement to prevent some edge cases. Who's keen to debug different SVG specs anyway?