Skip to content

BrandImage parser does not work with small images #3531

@guimou

Description

@guimou

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions