-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Use plain text in dataurl when possible #1843
Comments
This is likely a breaking change since there may be libraries that parse these URLs and only support base64 encoding. |
To be added, better read this: https://css-tricks.com/probably-dont-base64-svg Possible code to generate a safe dataurl string for svg (from antfu's blog, which is also from that css tricks post): // https://bl.ocks.org/jennyknuth/222825e315d45a738ed9d6e04c7a88d0
function encodeSvg(svg: string) {
return svg.replace('<svg', (~svg.indexOf('xmlns') ? '<svg' : '<svg xmlns="http://www.w3.org/2000/svg"'))
.replace(/"/g, '\'')
.replace(/%/g, '%25')
.replace(/#/g, '%23')
.replace(/{/g, '%7B')
.replace(/}/g, '%7D')
.replace(/</g, '%3C')
.replace(/>/g, '%3E')
}
const dataUri = `data:image/svg+xml;utf8,${encodeSvg(svg)}` |
There could be a separate loader for this then. Or a separate loader for current behaviour (still breaking, but with ability to fix easily). |
This has now been released! It would be helpful if someone with a real app could try this out and report back if it works or not. With the new behavior, esbuild is very aggressive with not percent-escaping things in order to reduce code size. I have tried to test this in browsers to see what the real requirements for escapes are and it doesn’t seem like many things actually need to be escaped (only |
The only issue that I have encountered with this change is with areas of my app using CSS-in-JS with SVG background images. import SomeBg from 'common/assets/images/SomeBg.svg';
import { css } from 'styled-components';
// Parse Error
css`
background: url(${SomeBg});
`;
// Works
css`
background: url('${SomeBg}');
`; I don't think it's mandatory per CSS spec to include quotes around the text inside the Thanks for making the change! |
Interesting breaking change: evanw/esbuild#1843
Interesting breaking change: evanw/esbuild#1843
Interesting breaking change: evanw/esbuild#1843
Interesting breaking change: evanw/esbuild#1843
Interesting breaking change: evanw/esbuild#1843
Interesting breaking change: evanw/esbuild#1843
When applying dataurl to a file that only contains valid utf-8 string it make sense, not to use base64.
For example
Now this produces these 197 bytes
But it could be 155:
The text was updated successfully, but these errors were encountered: