Don't trigger update for selection element mutations

This commit is contained in:
Marcel Mraz 2025-04-17 13:50:52 +02:00
parent 6668945282
commit 56fb7aec44
No known key found for this signature in database
GPG key ID: 4EBD6E62DC830CD2
10 changed files with 71 additions and 69 deletions

View file

@ -450,12 +450,13 @@ class Scene {
options,
);
// skip triggerUpdate if the element version hasn't changed
if (prevVersion === nextVersion) {
return element;
}
if (options.informMutation) {
if (
// skip if the element is not in the scene (i.e. selection)
this.elementsMap.has(element.id) &&
// skip if the element's version hasn't changed, as mutateElement returned the same element
prevVersion !== nextVersion &&
options.informMutation
) {
this.triggerUpdate();
}

View file

@ -423,6 +423,7 @@ export const maybeBindLinearElement = (
pointerCoords: { x: number; y: number },
scene: Scene,
): void => {
const elements = scene.getNonDeletedElements();
const elementsMap = scene.getNonDeletedElementsMap();
if (appState.startBoundElement != null) {
@ -436,7 +437,7 @@ export const maybeBindLinearElement = (
const hoveredElement = getHoveredElementForBinding(
pointerCoords,
scene.getNonDeletedElements(),
elements,
elementsMap,
appState.zoom,
isElbowArrow(linearElement),

View file

@ -10510,7 +10510,7 @@ class App extends React.Component<AppProps, AppState> {
shouldResizeFromCenter: false,
scene: this.scene,
zoom: this.state.zoom.value,
informMutation,
informMutation: false,
});
return;
}

View file

@ -1221,14 +1221,14 @@ exports[`contextMenu element > selecting 'Add to library' in context menu adds e
"roundness": {
"type": 3,
},
"seed": 453191,
"seed": 449462985,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 3,
"versionNonce": 1014066025,
"versionNonce": 1150084233,
"width": 20,
"x": -10,
"y": 0,
@ -1439,14 +1439,14 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings
"roundness": {
"type": 3,
},
"seed": 400692809,
"seed": 1014066025,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 3,
"versionNonce": 23633383,
"versionNonce": 1604849351,
"width": 20,
"x": 20,
"y": 30,
@ -1473,14 +1473,14 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings
"roundness": {
"type": 3,
},
"seed": 453191,
"seed": 449462985,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 4,
"versionNonce": 915032327,
"versionNonce": 23633383,
"width": 20,
"x": -10,
"y": 0,
@ -1774,14 +1774,14 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings
"roundness": {
"type": 3,
},
"seed": 400692809,
"seed": 1014066025,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 3,
"versionNonce": 23633383,
"versionNonce": 1604849351,
"width": 20,
"x": 20,
"y": 30,
@ -1808,14 +1808,14 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings
"roundness": {
"type": 3,
},
"seed": 453191,
"seed": 449462985,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 4,
"versionNonce": 915032327,
"versionNonce": 23633383,
"width": 20,
"x": -10,
"y": 0,
@ -2111,14 +2111,14 @@ exports[`contextMenu element > selecting 'Copy styles' in context menu copies st
"roundness": {
"type": 3,
},
"seed": 453191,
"seed": 449462985,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 3,
"versionNonce": 1014066025,
"versionNonce": 1150084233,
"width": 20,
"x": -10,
"y": 0,
@ -2327,14 +2327,14 @@ exports[`contextMenu element > selecting 'Delete' in context menu deletes elemen
"roundness": {
"type": 3,
},
"seed": 453191,
"seed": 449462985,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 4,
"versionNonce": 400692809,
"versionNonce": 1014066025,
"width": 20,
"x": -10,
"y": 0,
@ -2573,14 +2573,14 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates
"roundness": {
"type": 3,
},
"seed": 453191,
"seed": 449462985,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 3,
"versionNonce": 1014066025,
"versionNonce": 1150084233,
"width": 20,
"x": -10,
"y": 0,
@ -2607,14 +2607,14 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates
"roundness": {
"type": 3,
},
"seed": 400692809,
"seed": 1014066025,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 5,
"versionNonce": 1505387817,
"versionNonce": 400692809,
"width": 20,
"x": 0,
"y": 10,
@ -2885,14 +2885,14 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group
"roundness": {
"type": 3,
},
"seed": 453191,
"seed": 449462985,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 4,
"versionNonce": 81784553,
"versionNonce": 493213705,
"width": 20,
"x": -10,
"y": 0,
@ -2921,14 +2921,14 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group
"roundness": {
"type": 3,
},
"seed": 400692809,
"seed": 1014066025,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 4,
"versionNonce": 747212839,
"versionNonce": 915032327,
"width": 20,
"x": 20,
"y": 30,
@ -3253,14 +3253,14 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
"roundness": {
"type": 3,
},
"seed": 453191,
"seed": 449462985,
"strokeColor": "#e03131",
"strokeStyle": "dotted",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 4,
"versionNonce": 1402203177,
"versionNonce": 941653321,
"width": 20,
"x": -10,
"y": 0,
@ -3287,14 +3287,14 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
"roundness": {
"type": 3,
},
"seed": 1898319239,
"seed": 289600103,
"strokeColor": "#e03131",
"strokeStyle": "dotted",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 9,
"versionNonce": 941653321,
"versionNonce": 640725609,
"width": 20,
"x": 20,
"y": 30,
@ -3730,14 +3730,14 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e
"roundness": {
"type": 3,
},
"seed": 400692809,
"seed": 1014066025,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 4,
"versionNonce": 915032327,
"versionNonce": 23633383,
"width": 20,
"x": 20,
"y": 30,
@ -3764,14 +3764,14 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e
"roundness": {
"type": 3,
},
"seed": 453191,
"seed": 449462985,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 3,
"versionNonce": 1014066025,
"versionNonce": 1150084233,
"width": 20,
"x": -10,
"y": 0,
@ -4057,14 +4057,14 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el
"roundness": {
"type": 3,
},
"seed": 400692809,
"seed": 1014066025,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 4,
"versionNonce": 915032327,
"versionNonce": 23633383,
"width": 20,
"x": 20,
"y": 30,
@ -4091,14 +4091,14 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el
"roundness": {
"type": 3,
},
"seed": 453191,
"seed": 449462985,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 3,
"versionNonce": 1014066025,
"versionNonce": 1150084233,
"width": 20,
"x": -10,
"y": 0,
@ -4387,14 +4387,14 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung
"roundness": {
"type": 3,
},
"seed": 453191,
"seed": 449462985,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 5,
"versionNonce": 1006504105,
"versionNonce": 1723083209,
"width": 20,
"x": -10,
"y": 0,
@ -4421,14 +4421,14 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung
"roundness": {
"type": 3,
},
"seed": 1604849351,
"seed": 238820263,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 5,
"versionNonce": 289600103,
"versionNonce": 760410951,
"width": 20,
"x": 20,
"y": 30,
@ -5668,14 +5668,14 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi
"roundness": {
"type": 3,
},
"seed": 2019559783,
"seed": 453191,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 3,
"versionNonce": 1505387817,
"versionNonce": 1014066025,
"width": 10,
"x": -10,
"y": 0,
@ -5702,14 +5702,14 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi
"roundness": {
"type": 3,
},
"seed": 493213705,
"seed": 400692809,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 3,
"versionNonce": 747212839,
"versionNonce": 23633383,
"width": 10,
"x": 12,
"y": 0,
@ -6894,14 +6894,14 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro
"roundness": {
"type": 3,
},
"seed": 453191,
"seed": 449462985,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 4,
"versionNonce": 1723083209,
"versionNonce": 81784553,
"width": 10,
"x": -10,
"y": 0,
@ -6930,14 +6930,14 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro
"roundness": {
"type": 3,
},
"seed": 1604849351,
"seed": 238820263,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 4,
"versionNonce": 760410951,
"versionNonce": 747212839,
"width": 10,
"x": 12,
"y": 0,
@ -9821,14 +9821,14 @@ exports[`contextMenu element > shows context menu for element > [end of test] el
"roundness": {
"type": 3,
},
"seed": 453191,
"seed": 449462985,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 3,
"versionNonce": 1014066025,
"versionNonce": 1150084233,
"width": 20,
"x": -10,
"y": 0,

View file

@ -45,7 +45,7 @@ exports[`Test dragCreate > add element to the scene when pointer dragging long e
"type": "arrow",
"updated": 1,
"version": 4,
"versionNonce": 1150084233,
"versionNonce": 2019559783,
"width": 30,
"x": 30,
"y": 20,
@ -166,7 +166,7 @@ exports[`Test dragCreate > add element to the scene when pointer dragging long e
"type": "line",
"updated": 1,
"version": 4,
"versionNonce": 1150084233,
"versionNonce": 2019559783,
"width": 30,
"x": 30,
"y": 20,

View file

@ -134,7 +134,7 @@ exports[`move element > rectangles with binding arrow 5`] = `
"type": "rectangle",
"updated": 1,
"version": 4,
"versionNonce": 760410951,
"versionNonce": 1723083209,
"width": 100,
"x": 0,
"y": 0,
@ -173,7 +173,7 @@ exports[`move element > rectangles with binding arrow 6`] = `
"type": "rectangle",
"updated": 1,
"version": 7,
"versionNonce": 1051383431,
"versionNonce": 745419401,
"width": 300,
"x": 201,
"y": 2,
@ -231,7 +231,7 @@ exports[`move element > rectangles with binding arrow 7`] = `
"type": "arrow",
"updated": 1,
"version": 11,
"versionNonce": 1996028265,
"versionNonce": 1051383431,
"width": "86.85786",
"x": "107.07107",
"y": "47.07107",

View file

@ -50,7 +50,7 @@ exports[`multi point mode in linear elements > arrow 3`] = `
"type": "arrow",
"updated": 1,
"version": 8,
"versionNonce": 1604849351,
"versionNonce": 400692809,
"width": 70,
"x": 30,
"y": 30,
@ -106,7 +106,7 @@ exports[`multi point mode in linear elements > line 3`] = `
"type": "line",
"updated": 1,
"version": 8,
"versionNonce": 1604849351,
"versionNonce": 400692809,
"width": 70,
"x": 30,
"y": 30,

View file

@ -3980,7 +3980,7 @@ History {
exports[`regression tests > click-drag to select a group > [end of test] number of elements 1`] = `0`;
exports[`regression tests > click-drag to select a group > [end of test] number of renders 1`] = `15`;
exports[`regression tests > click-drag to select a group > [end of test] number of renders 1`] = `14`;
exports[`regression tests > deleting last but one element in editing group should unselect the group > [end of test] appState 1`] = `
{
@ -13569,7 +13569,7 @@ exports[`regression tests > switches from group of selected elements to another
"roundness": {
"type": 2,
},
"seed": 760410951,
"seed": 1723083209,
"strokeColor": "#1e1e1e",
"strokeStyle": "solid",
"strokeWidth": 2,

View file

@ -43,7 +43,7 @@ exports[`select single element on the scene > arrow 1`] = `
"type": "arrow",
"updated": 1,
"version": 4,
"versionNonce": 1150084233,
"versionNonce": 2019559783,
"width": 30,
"x": 10,
"y": 10,
@ -92,7 +92,7 @@ exports[`select single element on the scene > arrow escape 1`] = `
"type": "line",
"updated": 1,
"version": 4,
"versionNonce": 1150084233,
"versionNonce": 2019559783,
"width": 30,
"x": 10,
"y": 10,

View file

@ -256,7 +256,7 @@ describe("selection element", () => {
fireEvent.pointerMove(canvas, { clientX: 150, clientY: 30 });
expect(renderInteractiveScene).toHaveBeenCalledTimes(4);
expect(renderStaticScene).toHaveBeenCalledTimes(4);
expect(renderStaticScene).toHaveBeenCalledTimes(3);
const selectionElement = h.state.selectionElement!;
expect(selectionElement).not.toBeNull();
expect(selectionElement.type).toEqual("selection");
@ -279,7 +279,7 @@ describe("selection element", () => {
fireEvent.pointerUp(canvas);
expect(renderInteractiveScene).toHaveBeenCalledTimes(5);
expect(renderStaticScene).toHaveBeenCalledTimes(4);
expect(renderStaticScene).toHaveBeenCalledTimes(3);
expect(h.state.selectionElement).toBeNull();
});
});