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

Fix for when toObjects is called on a canvas with a clipPath #5556

Merged
merged 6 commits into from
Mar 15, 2019

Conversation

anthify
Copy link
Contributor

@anthify anthify commented Mar 5, 2019

Details

Regarding issue: #5549

Bugs

  • The private method _toObjectMethod is calling itself recursively if a clipPath is present on the root canvas.
  • In addition to that, it is called with the first argument being the clipPath klass object itself, instead of the expected argument String methodName, which breaks the subsequent to toObject method. The reason it breaks is because it's trying to find a method with methodName, but because it's an object it fails and throws an error.

Fix

  • remove the seemingly redundant recursive call of _toObjectMethod and instead apply the clipPath to the scoped variable data if clipPath exists, and returns that instead. This results in the expected behaviour when applying a clipPath with no errors.

@@ -1177,7 +1177,7 @@
objects: this._toObjects(methodName, propertiesToInclude),
};
if (clipPath) {
data.clipPath = this._toObjectMethod(clipPath, methodName, propertiesToInclude);
data.clipPath = this.clipPath;
Copy link
Member

Choose a reason for hiding this comment

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

wait, this should call _toOject anyway no?
In this way we are exporting the instance itself.
We want it's object representation.

anthify added 2 commits March 10, 2019 14:26
…sentation of clipPath object, without the klass prototype
… fix a seemingly unknown issue at the time attributed to the QUnit, but was in fact to do with the clipPath not having _toObject applied to it, thus it keeping the klass prototype, and not a plain JS object
@anthify
Copy link
Contributor Author

anthify commented Mar 14, 2019

@asturur changes to the test have been made now

@asturur asturur merged commit 3ac5207 into fabricjs:master Mar 15, 2019
@asturur
Copy link
Member

asturur commented Mar 15, 2019

thanks!

@melchiar
Copy link
Member

melchiar commented May 2, 2019

Hey guys, I just ran a quick test of this fix. While this does seem to resolve the issue with serializing a canvas with a clipPath, there appears to be a new bug when running loadFromJSON() on that output (see fiddle below).

Is this worth opening up a new issue?

image

http://jsfiddle.net/melchiar/68op1vLd/

@asturur
Copy link
Member

asturur commented May 2, 2019

i think there is a pr open for the load fix

@melchiar
Copy link
Member

melchiar commented May 2, 2019

ah thanks, I missed that - #5641

@asturur asturur mentioned this pull request May 19, 2019
thiagocunha pushed a commit to thiagocunha/fabric.js that referenced this pull request Nov 18, 2019
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

Successfully merging this pull request may close these issues.

3 participants