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

BrandImage parser does not work with small images #3531

Open
guimou opened this issue Nov 30, 2024 · 1 comment
Open

BrandImage parser does not work with small images #3531

guimou opened this issue Nov 30, 2024 · 1 comment

Comments

@guimou
Copy link
Member

guimou commented Nov 30, 2024

In the following code:

const parsed = parser.parseFromString(src, 'text/xml');

the parser checks for XML errors.

However I found that the check always fails with small images. (took me a while to figure this out...)

That's because since Webpack 5, asset modules have a default size threshold (usually 8 KB). So if an SVG file is smaller than this threshold, it is directly inlined as a data:image/svg+xml;... URI. Larger SVGs are emitted as separate files.

So as small files sources are already inlined/converted, the following is not necessary (on top of the Parser check failing):

newSrc = `data:image/svg+xml;base64,${btoa(src)}`;

Two choices:

  • Modify the component to check for src type first before trying to inline it.
  • Modify webpack configuration to never inline SVGs as data. However, this may break some other components...
@guimou
Copy link
Member Author

guimou commented Nov 30, 2024

The error may not be in this check. In fact, although image.isValid is always true whatever the source of the image (url or inline), this return is always triggered by inline images:

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

1 participant