-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
fix: copy static image as it is if image compression fail #887
Conversation
Deploy preview for docusaurus-preview ready! Built with commit dfc0619 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
It would be interesting to see what errors are being thrown at random times to cause images not to compress correctly.
On that note, do you think having the image compression functionality is still useful for us? Or is it causing more problems than it helps?
@@ -247,11 +247,9 @@ async function execute() { | |||
!commander.skipImageCompression | |||
) { | |||
const parts = normalizedFile.split(`${sep}static${sep}`); | |||
const targetDirectory = join( | |||
buildDir, | |||
parts[1].substring(0, parts[1].lastIndexOf(sep)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this always wrong? I see you removed this from your update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really wrong but this is not declarative enough. I think using function from nodejs path clearly shows the intent.
const targetDirectory = path.dirname(targetFile);
The previous code in the below section
mkdirp.sync(path.dirname(targetDirectory));
is wrong though. It should be
mkdirp.sync(targetDirectory);
@JoelMarcey i think it definitely help in the sense that it reduces the website loading page since image size is reduced. It's causing problem because we completely skip that image if compression is failing. Ex: #701 |
It still fails but at least the image is now intact and image is copied to build. Here is the error printed:
|
Bad image? Or buggy compressor? Sent with GitHawk |
@JoelMarcey I think it should copy in either cases ... I didn't notice that case would happen to be honest |
Motivation
Fix #701
There is no error handling on https://github.com/facebook/Docusaurus/blob/ef80581e8ef950a0865fc7851407c672c4bbd510/lib/server/generate.js#L255-L264
If the image compression fails, it will cause the image to be missing.
Example:
https://circleci.com/gh/facebook/Docusaurus/2846
The build succeed but along the line there is an unhandled promise. Causing
christopher-chedeau.jpg
andricky-vetter.jpg
to be missing.This PR add a fallback functionality to copy the image as it is if the image compression fail
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
https://deploy-preview-887--docusaurus-preview.netlify.com/
Related PRs
#654