Skip to content

Commit 62ba23e

Browse files
committed
MC-4217: Performance of show/hide Slider on stage is very slow
- Don’t rebuild Slick when any data changes, only rebuild when selected options are changed
1 parent b43823b commit 62ba23e

File tree

2 files changed

+68
-2
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

2 files changed

+68
-2
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/slider/preview.js

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/slider/preview.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ export default class Preview extends PreviewCollection {
4848
private afterChildrenRenderDeferred: DeferredInterface = deferred();
4949
private buildSlickDebounce = _.debounce(this.buildSlick.bind(this), 10);
5050

51+
/**
52+
* Define keys which when changed should not trigger the slider to be rebuilt
53+
*
54+
* @type {string[]}
55+
*/
56+
private ignoredKeysForBuild: string[] = [
57+
"display",
58+
"margins_and_padding",
59+
"border",
60+
"border_color",
61+
"border_radius",
62+
"border_width",
63+
"css_classes",
64+
"name",
65+
"text_align",
66+
];
67+
private previousData: DataObject;
68+
5169
/**
5270
* @param {ContentTypeCollectionInterface} parent
5371
* @param {ContentTypeConfigInterface} config
@@ -73,7 +91,13 @@ export default class Preview extends PreviewCollection {
7391
this.element = element as HTMLElement;
7492

7593
this.childSubscribe = this.parent.children.subscribe(this.buildSlickDebounce);
76-
this.parent.dataStore.subscribe(this.buildSlickDebounce);
94+
this.previousData = this.parent.dataStore.get() as DataObject;
95+
this.parent.dataStore.subscribe((data: DataObject) => {
96+
if (this.hasDataChanged(this.previousData, data)) {
97+
this.buildSlickDebounce();
98+
}
99+
this.previousData = data;
100+
});
77101

78102
this.buildSlick();
79103

@@ -346,6 +370,19 @@ export default class Preview extends PreviewCollection {
346370
});
347371
}
348372

373+
/**
374+
* Determine if the data has changed, whilst ignoring certain keys which don't require a rebuild
375+
*
376+
* @param {DataObject} previousData
377+
* @param {DataObject} newData
378+
* @returns {boolean}
379+
*/
380+
private hasDataChanged(previousData: DataObject, newData: DataObject) {
381+
previousData = _.omit(previousData, this.ignoredKeysForBuild);
382+
newData = _.omit(newData, this.ignoredKeysForBuild);
383+
return !_.isEqual(previousData, newData);
384+
}
385+
349386
/**
350387
* Build our instance of slick
351388
*/

0 commit comments

Comments
 (0)