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) Ensure the abortable signal is passed down to objects #9890

Merged
merged 5 commits into from
May 24, 2024
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(Group): Pass down the abort signal from group to objects [#9890](https://github.com/fabricjs/fabric.js/pull/9890)
- fix(util): restore old composeMatrix code for performances improvement [#9851](https://github.com/fabricjs/fabric.js/pull/9851)
- fix(Control): corner coords definition order [#9884](https://github.com/fabricjs/fabric.js/pull/9884)
- fix(Polyline): safeguard points arg from options [#9855](https://github.com/fabricjs/fabric.js/pull/9855)
Expand Down
22 changes: 22 additions & 0 deletions src/shapes/Group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Group } from './Group';
import type { GroupProps } from './Group';
import { Rect } from './Rect';
import { FabricObject } from './Object/FabricObject';
import { FabricImage } from './Image';
import { SignalAbortedError } from '../util/internals/console';

const makeGenericGroup = (options?: Partial<GroupProps>) => {
const objs = [new FabricObject(), new FabricObject()];
Expand Down Expand Up @@ -58,6 +60,26 @@ describe('Group', () => {
expect(group.height).toBe(100);
});

it('fromObject with images', async () => {
const objs = [
new FabricObject(),
new FabricObject(),
new FabricImage(new Image()),
];
const group = new Group(objs);
const jsonData = group.toObject();
const abortController = new AbortController();
abortController.abort();
return Group.fromObject(jsonData, {
signal: abortController.signal,
}).catch((e) => {
expect(e instanceof SignalAbortedError).toBe(true);
expect(e.message).toBe(
`fabric: loadImage 'options.signal' is in 'aborted' state`
);
});
});

describe('With fit-content layout manager', () => {
test('will serialize correctly without default values', async () => {
const { group } = makeGenericGroup({
Expand Down
21 changes: 12 additions & 9 deletions src/shapes/Group.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { CollectionEvents, ObjectEvents } from '../EventTypeDefs';
import { createCollectionMixin } from '../Collection';
import type { TClassProperties, TSVGReviver, TOptions } from '../typedefs';
import type {
TClassProperties,
TSVGReviver,
TOptions,
Abortable,
} from '../typedefs';
import {
invertTransform,
multiplyTransformMatrices,
Expand Down Expand Up @@ -658,15 +663,13 @@ export class Group
* @param {Object} object Object to create a group from
* @returns {Promise<Group>}
*/
static fromObject<T extends TOptions<SerializedGroupProps>>({
type,
objects = [],
layoutManager,
...options
}: T) {
static fromObject<T extends TOptions<SerializedGroupProps>>(
{ type, objects = [], layoutManager, ...options }: T,
abortable?: Abortable
) {
return Promise.all([
enlivenObjects<FabricObject>(objects),
enlivenObjectEnlivables(options),
enlivenObjects<FabricObject>(objects, abortable),
enlivenObjectEnlivables(options, abortable),
]).then(([objects, hydratedOptions]) => {
const group = new this(objects, {
...options,
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/Image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ export class FabricImage<
*/
static fromObject<T extends TOptions<SerializedImageProps>>(
{ filters: f, resizeFilter: rf, src, crossOrigin, type, ...object }: T,
options: Abortable = {}
options?: Abortable
) {
return Promise.all([
loadImage(src!, { ...options, crossOrigin }),
Expand Down
Loading