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(): bubble dirty flag #9540

Merged
merged 6 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading