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(Group): remove added object from canvas #8034

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ShaMan123
Copy link
Contributor

@ShaMan123 ShaMan123 commented Jun 29, 2022

This PR safeguards group.add from a case which the added object belongs to a canvas and vice versa

ActiveSelection should conform to this logic IMO, though currently this bug is prevented because the selected objects are filtered out from the rendered objects in the render cycle.

Meaning a case in which an object is shared between 2 canvases and is selected by one is a hole in the logic. I can code something to patch this but I don't think it's needed 'cause were talking about a super edge case (which I think states the dev is handling heavy customization so tough luck for them) EDITED OK that's wrong. An object won't be selected if it doesn't belong to canvas or a group in it (only programmatically) . So this isn't really a case

@github-actions
Copy link
Contributor

github-actions bot commented Jun 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  |    83.2 |    76.18 |   85.85 |   82.94 |                                               
 fabric.js |    83.2 |    76.18 |   85.85 |   82.94 | ...,30853,30927,30938-31003,31126,31225,31461 
-----------|---------|----------|---------|---------|-----------------------------------------------

@ShaMan123
Copy link
Contributor Author

It's very nice that tests simply pass (without firefox failing)

@stale
Copy link

stale bot commented Jul 30, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue marked as stale by the stale bot label Jul 30, 2022
@ShaMan123 ShaMan123 removed the stale Issue marked as stale by the stale bot label Aug 1, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2022

Coverage after merging add-to-group-safeguard into master will be

82.44%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
HEADER.js54%48.15%0%63.64%12, 14, 14, 14, 14, 14, 16–17, 21, 21–22, 22, 22, 24, 24, 26, 28, 30–31, 77, 77, 77
src
   cache.ts97.06%90%100%100%57
   canvas.class.ts93.36%90.22%94.12%95.54%1045, 1045–1046, 1049, 1069, 1069, 1104, 1137–1138, 1166–1167, 1200, 1208, 1318–1319, 1321–1322, 1342–1343, 1501, 1506, 1516, 1520, 472–473, 478, 487, 636–638, 683–684, 733–734, 737, 739, 782–784, 826, 831–832, 860–861
   config.ts77.27%66.67%66.67%84.62%130, 138–140, 151–153
   constants.ts100%100%100%100%
   intersection.class.ts100%100%100%100%
   pattern.class.ts92.19%85.71%100%96.30%110, 116, 127, 136, 88
   point.class.ts100%100%100%100%
   shadow.class.ts95.95%90%100%100%173, 240, 9
   static_canvas.class.ts90.43%84.37%96.88%92.96%1189–1190, 1190, 1190–1191, 1325, 1391–1392, 1395, 1444–1445, 1538, 1553, 1557, 1583–1584, 1613–1614, 1647–1648, 1689–1690, 1693, 1695, 1695, 1695, 1695, 1699, 1699, 1699–1701, 1723–1724, 1765–1766, 1769, 1771, 1771, 1771, 1771, 1775, 1775, 1775–1777, 1850, 1850–1851, 1924, 1926, 1926, 1926, 1926, 1926–1927, 1930–1931, 1931, 1931–1932, 1935, 1935, 1935, 1937, 1940, 1946, 1948–1949, 1949, 1949, 1952–1953, 1953, 1953, 1956, 279–280, 282–283, 285–286, 299–300, 302–303, 634, 668, 735–738, 938
src/brushes
   base_brush.class.ts100%100%100%100%
   circle_brush.class.ts2.99%0%0%3.92%100–101, 103, 105–107, 116, 116, 116, 118, 120, 122–124, 126–129, 137, 144, 146, 26, 31–32, 40–44, 48–52, 59–62, 70–74, 76, 84, 84, 84, 84, 84–85, 87, 87, 87–90, 92
   pattern_brush.class.ts5.26%0%0%8.33%16, 20–23, 25–26, 26, 26–29, 37–38, 40, 44, 55, 55, 55, 63–65, 65, 65, 72–73, 75–76, 76, 80
   pencil_brush.class.ts91.95%85.42%100%93.69%125–126, 155, 155–157, 279, 283, 288–289, 71–72, 87–88
   spray_brush.class.ts2.30%0%0%3.08%102–104, 106–107, 115, 115, 115, 115, 115–116, 118–119, 126–127, 129, 131–135, 144, 148–149, 149, 157, 157, 157–160, 162–165, 169–170, 172, 174–177, 180, 187–188, 190, 192–193, 195, 202–203, 205–206, 209, 209, 216, 216, 220, 25–26, 28–30, 30, 30–32, 36, 45, 52, 59, 66, 73, 80, 92–94
src/color
   color.class.ts91.67%84.51%100%94.44%325–326, 330–331, 334–335, 41, 45, 72–73, 73, 75, 75, 75–76, 78–79
   color_map.ts100%100%100%100%
   constants.ts100%100%100%100%
   index.ts100%100%100%100%
   util.ts100%100%100%100%
src/controls
   actions.ts100%100%100%100%
   changeWidth.ts100%100%100%100%
   control.class.ts93.98%88.89%90.91%97.78%236, 320, 320, 355
   controls.render.ts81.63%78%100%84.78%106, 111, 121, 121, 45, 50, 61, 61, 65–72, 81–82
   default_controls.ts72.73%50%100%100%109, 113, 120
   drag.ts100%100%100%100%
   rotate.ts20%12.50%50%22.22%44, 50, 50, 50–51, 54–56, 58, 58, 58, 58, 58–60, 60, 60–62, 64, 64, 64–66, 66, 66–67, 72, 72, 72–73, 75, 77, 79–80
   scale.ts94.41%94.74%100%93.59%129–130, 132–134, 181–183, 42
   scaleSkew.ts80.56%66.67%100%92.31%14, 28, 30, 30, 30, 32, 34
   skew.ts91.03%79.31%100%97.67%131–132, 163–164, 171, 177, 179
   util.ts100%100%100%100%
   wrapWithFireEvent.ts100%100%100%100%
   wrapWithFixedAnchor.ts100%100%100%100%
src/filters
   2d_backend.class.ts96.43%83.33%100%100%78
   WebGLProbe.ts40%40%57.14%34.78%38–39, 49–53, 61, 64, 66, 66, 66–67, 67, 67–70, 72, 74, 78
   base_filter.class.ts28.90%31.82%36.36%26.17%100–102, 102, 102–103, 112–116, 116, 116–117, 124–125, 125, 125–128, 143, 159, 169–174, 178, 181, 181, 181–184, 184, 184–185, 185, 188–189, 195, 204–205, 210–214, 257–260, 273, 273, 273–274, 276, 292–294, 294, 294, 294, 294–295, 297, 299–300, 306–307, 309–311, 315–316, 318, 322–324, 328, 332, 352, 352, 352–356, 393, 78, 78, 78–79, 79, 79–80, 80, 80–81, 86–89, 89, 89–90, 99
   blendcolor_filter.class.ts10%4.76%28.57%9.72%104, 126, 128, 128, 128–130, 135, 145–147, 155, 157–160, 162–165, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 169–172, 174–177, 179–182, 185–188, 190–193, 195–198, 200–203, 205–206, 206, 209–210,

Comment on lines 633 to 638
else if (object.canvas) {
/* _DEV_MODE_START_ */
console.warn('fabric.Canvas: removing object from canvas before entering another', object, object.canvas, this);
/* _DEV_MODE_END_ */
object.canvas.remove(object);
}
Copy link
Member

Choose a reason for hiding this comment

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

in my opinion this should be executed always, not just with an else if.
What if it was in a group, on another canvas?
In that case the older canvas has a reference to an invalid object.
if we are safeguarding, we should remove from group and from canvas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if it was in a group, on another canvas?

I that case the first if block will catch it and Group#remove will clear refs.
Else if is necessary since we are checking for a parent and because an object always has a ref to canvas (even if not a direct child of canvas) we call tell if canvas is the parent or not only by checking if the group ref isn't empty.
I introduced getParent in a pending group PR for this purpose exactly.
Then it can become

object.getParent()?.remove(object)

Comment on lines 268 to 273
else if (object.canvas) {
/* _DEV_MODE_START_ */
console.warn('fabric.Group: removing object from canvas before entering group', object, object.canvas, this);
/* _DEV_MODE_END_ */
object.canvas.remove(object);
}
Copy link
Member

Choose a reason for hiding this comment

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

as the comment below, this check seems necessary in every case

@asturur
Copy link
Member

asturur commented Sep 3, 2022

Forgot about this small pr.
There are 2 comments but otherwise looks good

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.

merge conflict artifact found

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.

Updated from master and resolved conflicts

@ShaMan123
Copy link
Contributor Author

@asturur up

@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2022

Build Stats

file / KB (diff) bundled reduced* minified gzipped
fabric.min.js 1112.976 (+1.196) 334.241 (+0.689) 93.638 (+0.183)
src/shapes/group.class.ts 36.519 (+0.301) 38.314 (+0.193)
src/static_canvas.class.ts 62.174 (+1.130) 65.160 (+1.003)

*inaccurate, see link

@asturur
Copy link
Member

asturur commented Jan 14, 2024

those fix where committed with other PRs, i see them inside the codebase

@asturur asturur closed this Jan 14, 2024
Comment on lines +302 to +309
} else if (object.canvas) {
console.warn(
'fabric.Group: removing object from canvas before entering group',
object,
object.canvas,
this
);
object.canvas.remove(object);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not in master @asturur

@ShaMan123 ShaMan123 reopened this May 6, 2024
@ShaMan123
Copy link
Contributor Author

This Pr needs porting but should enter rc ASAP

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.

2 participants