Skip to content

Commit

Permalink
fix(): dirty flag bubbling for group (#9540)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 authored Dec 11, 2023
1 parent 7154d14 commit b597bb5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- fix(): bubble dirty flag for group only when true [#9540](https://github.com/fabricjs/fabric.js/pull/9540)
- test() Backport a test to capture a failing text style situation [#9531](https://github.com/fabricjs/fabric.js/pull/9531)

## [6.0.0-beta16]
Expand Down
19 changes: 19 additions & 0 deletions src/shapes/Object/Object.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Shadow } from '../../Shadow';
import { Rect } from '../Rect';
import { FabricObject } from './Object';
import { Group } from '../Group';

describe('Object', () => {
it('rotate with centered rotation', () => {
Expand Down Expand Up @@ -100,4 +101,22 @@ describe('Object', () => {
expect(rect.needsItsOwnCache()).toBe(false);
});
});
describe('set method and dirty flag bubbling', () => {
it('when dirty is true it bubbles', () => {
const rect = new Rect({ width: 100, height: 100 });
const group = new Group([rect]);
group.dirty = false;
expect(group.dirty).toBe(false);
rect.set('dirty', true);
expect(group.dirty).toBe(true);
});
it('when dirty is false it does not bubble', () => {
const rect = new Rect({ width: 100, height: 100 });
const group = new Group([rect]);
group.dirty = true;
expect(group.dirty).toBe(true);
rect.set('dirty', false);
expect(group.dirty).toBe(true);
});
});
});
5 changes: 4 additions & 1 deletion src/shapes/Object/Object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,10 @@ export class FabricObject<
// i don't like this automatic initialization here
} else if (key === 'shadow' && value && !(value instanceof Shadow)) {
value = new Shadow(value);
} else if (key === 'dirty' && this.group) {
} else if (key === 'dirty' && this.group && value) {
// a dirty child makes the parent dirty
// but a non dirty child will not make the parent non dirty.
// the parent could be dirty for some other reason
this.group.set('dirty', value);
}

Expand Down

0 comments on commit b597bb5

Please sign in to comment.