Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

Fix image loading issue in v5 of lottie-web #14

Closed
wants to merge 5 commits into from

Conversation

razvanmitre
Copy link

@razvanmitre razvanmitre commented Mar 17, 2021

Fixes issue #8

Copy link
Owner

@friday friday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for this PR. I haven't tested myself, but if it fixes the image loading issue that's awesome for lottie-node, and makes it a viable option again 👍. I haven't used lottie-node myself for years, so I haven't kept track of upstream changes. It seems Lottie-web broke compatibility with lottie-node at some point, by refactoring. That was not unexpected, given lottie-node is pretty much a hack. I think I even warned about that in the readme.

I'll be happy to merge this, but first need some changes or answers.

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "lottie-node",
"version": "1.0.0",
"version": "1.1.0",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never change this in a pull request. This is for the maintainer to decide. It's also a breaking change (not backward compatible), so the major number should be changed (v2, not v1.1.0)

const {JSDOM} = require('jsdom');
const {Canvas} = require('canvas');
const { JSDOM } = require('jsdom');
const { Canvas } = require('canvas');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change and also row 30, 35, 58 and 60 are formatting only, and you shouldn't do that when contributing to other people code. At least ask first. It also makes your PR harder to merge if people make formatting changes, especially if many people do.

If you do want to propose cleaning up/improving the formatting (I don't mind), that should be a separate PR, or at least separate commit.

const {window} = new JSDOM('', {pretendToBeVisual: true});
const {document, navigator} = window;
const {Image} = Canvas;
const { window } = new JSDOM('', { pretendToBeVisual: true, "resources": "usable" });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"resources": "usable" sounds like a good option 👍. I'm not sure if it's new or I missed it before.

assetData: assetData,
};

require('canvas').loadImage(path).then((image) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Canvas is already required, and if you need to use loadImage you can add that to line 4 instead const { Canvas, loadImage } = require('canvas');

Require should always be unconditional and on top if possible "Since require() does a synchronous load, it can cause performance problems when used in other locations." -eslint rule

const createContent = `
function createImgData(assetData) {
var path = getAssetsPath(assetData, this.assetsPath, this.path);
var ob = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index.js Outdated
ob.img = image;
this._imageLoaded();
}).catch((err) => {
ob.img = proxyImage;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is proxyImage? It's not defined anywhere.

this._imageLoaded();
});

return ob;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns ob before the image is loaded and assigned to ob.img. Is this safe?

@friday
Copy link
Owner

friday commented Apr 7, 2021

Rather than accepting this PR which comes with too many changes I don't want I cherry-picked the new image loading method in 6cb9be7 Thanks for the fix!

This PR and that commit doesn't actually fix #8. This fixes Lottie breaking compatibility with our image loading code injection, which is more serious I guess.

I didn't need resources: "usable", so I left it out.

@friday friday closed this Apr 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants