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(canvas export): regression caused by safegurading #7907

Merged
merged 7 commits into from
Apr 30, 2022

Conversation

ShaMan123
Copy link
Contributor

#7866 exposed a regression when using toCanvasElement
This commit fixes it by working around canvas.add and fixes another issue:
object.toCanvasElement() would fire an added event which is absolutely undesired

#7866 exposed a regression when using `toCanvasElement`
This commit fixes it and fixes another issue:
`object.toCanvasElement()` would fire an added event which is absolutely undesired
@ShaMan123 ShaMan123 requested a review from asturur April 26, 2022 09:06
@github-actions
Copy link
Contributor

github-actions bot commented Apr 26, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.92 |    75.36 |   86.25 |   82.63 |                                               
 fabric.js |   82.92 |    75.36 |   86.25 |   82.63 | ...,30453,30527,30538-30603,30726,30825,31061 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Apr 26, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.92 |    75.36 |   86.25 |   82.63 |                                               
 fabric.js |   82.92 |    75.36 |   86.25 |   82.63 | ...,30453,30527,30538-30603,30726,30825,31061 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Apr 26, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.97 |    75.39 |   86.25 |   82.68 |                                               
 fabric.js |   82.97 |    75.39 |   86.25 |   82.68 | ...,30456,30530,30541-30606,30729,30828,31064 
-----------|---------|----------|---------|---------|-----------------------------------------------

@ShaMan123 ShaMan123 changed the title fix(canvas export): safegurad conflict fix(canvas export): regression caused by safegurad conflict Apr 26, 2022
@ShaMan123 ShaMan123 changed the title fix(canvas export): regression caused by safegurad conflict fix(canvas export): regression caused by safegurading Apr 26, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 26, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.92 |    75.36 |   86.25 |   82.63 |                                               
 fabric.js |   82.92 |    75.36 |   86.25 |   82.63 | ...,30456,30530,30541-30606,30729,30828,31064 
-----------|---------|----------|---------|---------|-----------------------------------------------

@ShaMan123 ShaMan123 mentioned this pull request Apr 26, 2022
48 tasks
@github-actions
Copy link
Contributor

github-actions bot commented Apr 26, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.92 |    75.36 |   86.25 |   82.63 |                                               
 fabric.js |   82.92 |    75.36 |   86.25 |   82.63 | ...,30456,30530,30541-30606,30729,30828,31064 
-----------|---------|----------|---------|---------|-----------------------------------------------

canvas.add(this);
var canvasEl = canvas.toCanvasElement(multiplier || 1, options);
this.shadow = originalShadow;
this.set('canvas', canvas);
Copy link
Member

Choose a reason for hiding this comment

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

switching from add to set('canvas') don't we miss a setCoords on the object that could be necessary for proper rendering?

Copy link
Member

Choose a reason for hiding this comment

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

i would add a setCoords here, just to be sure we change with something is equivalent

Copy link
Member

@asturur asturur Apr 26, 2022

Choose a reason for hiding this comment

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

Also, what about we do:
canvas._objects = [this] since this is a trash-away canvas and we avoid adding an extra options to toDataUrl?

When adding this option here:
https://github.com/fabricjs/fabric.js/pull/7907/files#diff-6748525f6b3662ac6540af0ceab4cbcd5e5d44069b54ec0b1c3d9edab1e894ecR64

Is unclear that passing the objects in, those have to have a canvas reference properly set and setCoords done.
Is just an open door for misunderstandings. let's solve it inside the object.toDataUrl function and leave the rest as it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

i think i would needed because if the object in question has offscreen coords, it will eventually not be drawn.
Since it needs to be drawn ( the whole reason of the dataurl export ) and coords can influence a drawing skip, and since we were implicitly setting them using add, i would continue setting them.
The coords are indeed reset at the end of the function. If we don't change them, there would be at least no reason to set them again.

Copy link
Contributor Author

@ShaMan123 ShaMan123 Apr 26, 2022

Choose a reason for hiding this comment

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

de494ae6278212520cae6374e5a8eecaa8d08248ab53f6f30c167949186292caR1726

skipOffscreen: false, so it should not happen

@asturur
Copy link
Member

asturur commented Apr 26, 2022

What was the new issue?
I understand there was a past issue that was firing an extra added event.
is the new issue that now we are actually removing an object from the canvas, so going back to the original one is not working anymore?

@ShaMan123
Copy link
Contributor Author

The new issue was that the safeguarding logic removed the canvas ref from the StaticCanvas#add method and caused a bug when using with toCanvasElement

@asturur
Copy link
Member

asturur commented Apr 26, 2022

yes but which is the bug ? I think it is that it would missing in the object array of the original canvas, is it that?

@github-actions
Copy link
Contributor

github-actions bot commented Apr 26, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.97 |    75.38 |   86.25 |   82.69 |                                               
 fabric.js |   82.97 |    75.38 |   86.25 |   82.69 | ...,30456,30530,30541-30606,30729,30828,31064 
-----------|---------|----------|---------|---------|-----------------------------------------------

@ShaMan123
Copy link
Contributor Author

ShaMan123 commented Apr 26, 2022

It surfaced when I merged #7802 with #7859 I think. The drag image uses toCanvasElement - it was there.
Strange things happened and the selected/exported object disappeared

@github-actions
Copy link
Contributor

github-actions bot commented Apr 26, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.92 |    75.36 |   86.25 |   82.63 |                                               
 fabric.js |   82.92 |    75.36 |   86.25 |   82.63 | ...,30456,30530,30541-30606,30729,30828,31064 
-----------|---------|----------|---------|---------|-----------------------------------------------

@ShaMan123 ShaMan123 requested a review from asturur April 26, 2022 14:26
Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

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

ready

@ShaMan123 ShaMan123 requested a review from asturur April 29, 2022 03:09
@github-actions
Copy link
Contributor

github-actions bot commented Apr 29, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.93 |    75.35 |   86.25 |   82.64 |                                               
 fabric.js |   82.93 |    75.35 |   86.25 |   82.64 | ...,30458,30532,30543-30608,30731,30830,31066 
-----------|---------|----------|---------|---------|-----------------------------------------------

@asturur asturur merged commit 06de045 into master Apr 30, 2022
@ShaMan123 ShaMan123 deleted the fix-canvas-export-safegurad-conflict branch September 11, 2022 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants