facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
54.22k stars 8.13k forks source link

Seeing warnings about unsupported file type: undefined for SVG images #9715

Open dabeeeenster opened 6 months ago

dabeeeenster commented 6 months ago

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

When running npm run build after upgrading to docusaurus 3.1.0 I have started seeing the following WARNING errors in the console:

[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/saas-architecture.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/saas-architecture.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/flagsmith-model.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/flagsmith-model.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/flagsmith-model.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/flagsmith-model.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/saas-architecture.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/saas-architecture.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/sdk-remote-evaluation.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/sdk-remote-evaluation.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/sdk-local-evaluation.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/sdk-local-evaluation.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/self-hosted-architecture.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/sdk-remote-evaluation.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/sdk-remote-evaluation.svg)
[WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/sdk-local-evaluation.svg" can't be read correctly. Please ensure it's a valid image.
unsupported file type: undefined (file: /Users/ben/flagsmith/flagsmith/docs/static/img/sdk-local-evaluation.svg)

You can find the images referenced here: https://github.com/Flagsmith/flagsmith/tree/main/docs/static/img e.g. https://github.com/Flagsmith/flagsmith/blob/main/docs/static/img/self-hosted-architecture.svg

These are optimised SVG images but they are valid and display fine in browsers.

Reproducible demo

https://github.com/Flagsmith/flagsmith/pull/3246

Steps to reproduce

  1. Run npm run build
  2. See warning about SVGs

Expected behavior

No warning should show as the images are valid

Actual behavior

Receive warnings [WARNING] The image at "/Users/ben/flagsmith/flagsmith/docs/static/img/saas-architecture.svg" can't be read correctly. Please ensure it's a valid image.

Your environment

Self-service

slorber commented 6 months ago

Can you create 2 minimal runnable repros?

I doubt it's the upgrade that led this warning to appear, because the new release doesn't contain any code change related to this.

My believe is that this warning has likely always been there, when you reference svgs in markdown content.

I'd kindly ask you to invest time to qualify better this potential bug.

dabeeeenster commented 6 months ago

Ah yes you are correct @slorber ! It was my clearing the build cache that caused the warnings to reappear. I'm still not clear why they are being thrown however? I believe the SVG files are valid?

slorber commented 6 months ago

Ah yes you are correct @slorber ! It was my clearing the build cache that caused the warnings to reappear. I'm still not clear why they are being thrown however? I believe the SVG files are valid?

That's likely a bug related to using svg files using markdown image syntax.

CleanShot 2024-01-08 at 19 16 37@2x

We should probably find a way to read the dimensions of local svg files to apply them to the <img> tag, so that it doesn't produce layout shifts when the svgs load.

Hmm apparently our lib "image-size" is supposed to handle svgs as well, so it's probably a bug in this library.

https://github.com/image-size/image-size

Can you provide a sample SVG? Can you try reading its dimensions with that lib?

dabeeeenster commented 6 months ago

OK yep https://gist.github.com/dabeeeenster/004e82c3e344707751f294c16d5ddf50 shows the error being thrown in that library - issue raised here.

damageboy commented 3 months ago

FWIW, I have the same issue with editable svg's saved with draw.io.

For now my solution is to add a build step that is invoked before yarn build:

# finds all .svg files and passes them to xargs to paraellelize
# svgo-ing them in groups of 10 (this avoids paying nodejs JIT time for every file)
fd -e svg -0 | xargs -0 -P $(nproc) -n 10 svgo                                                                                                              ─╯
Airkro commented 1 month ago

Pin image-size to v1.0.x fix this:

// package.json
{
  "devDependencies": {
    "image-size": "~1.0.2"
  }
}