Skip to content

Commit 01b1631

Browse files
committed
PB-390: Nested Page Builder content can fail to save when action is performed quickly
- Debounce request inside frame - Only post message the last request into the frame
1 parent 3c49bf5 commit 01b1631

File tree

2 files changed

+44
-13
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

2 files changed

+44
-13
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/master-format/render/frame.js

Lines changed: 23 additions & 7 deletions
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/master-format/render/frame.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import $ from "jquery";
77
import ko from "knockout";
88
import engine from "Magento_Ui/js/lib/knockout/template/engine";
9+
import mageUtils from "mageUtils";
910
import _ from "underscore";
1011
import Config from "../../config";
1112
import ConfigInterface from "../../config.types";
@@ -19,6 +20,24 @@ import { TreeItem } from "./serialize";
1920
let port: MessagePort = null;
2021
const portDeferred: JQueryDeferred<MessagePort> = $.Deferred();
2122
const deferredTemplates: {[key: string]: JQueryDeferred<string>} = {};
23+
let lastRenderId: string;
24+
25+
/**
26+
* Debounce the render call, so we don't render until the final request
27+
*/
28+
const debounceRender = _.debounce((message: {stageId: string, tree: TreeItem}) => {
29+
const renderId = mageUtils.uniqueid();
30+
lastRenderId = renderId;
31+
render(message).then((output) => {
32+
// Only post the most recent render back to the parent
33+
if (lastRenderId === renderId) {
34+
port.postMessage({
35+
type: "render",
36+
message: output,
37+
});
38+
}
39+
});
40+
}, 50);
2241

2342
/**
2443
* Listen for requests from the parent window for a render
@@ -39,12 +58,7 @@ export default function listen(config: ConfigInterface) {
3958
portDeferred.resolve(port);
4059
port.onmessage = (messageEvent) => {
4160
if (messageEvent.data.type === "render") {
42-
render(messageEvent.data.message).then((output) => {
43-
port.postMessage({
44-
type: "render",
45-
message: output,
46-
});
47-
});
61+
debounceRender(messageEvent.data.message);
4862
}
4963
if (messageEvent.data.type === "template") {
5064
const message = messageEvent.data.message;
@@ -141,6 +155,7 @@ function render(message: {stageId: string, tree: TreeItem}) {
141155

142156
// Combine this event with our engine waitForRenderFinish to ensure rendering is completed
143157
$.when(engine.waitForFinishRender(), renderFinished).then(() => {
158+
console.log("count " + countContentTypes(rootContainer));
144159
observer.disconnect();
145160
ko.cleanNode(element);
146161
const filtered: JQuery = filterHtml($(element));

0 commit comments

Comments
 (0)