Skip to content

Commit 7527c42

Browse files
committed
PB-390: Nested Page Builder content can fail to save when action is performed quickly
1 parent 2d9d981 commit 7527c42

File tree

3 files changed

+75
-68
lines changed

3 files changed

+75
-68
lines changed

app/code/Magento/PageBuilder/etc/db_schema.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<column xsi:type="int" name="template_id" identity="true" comment="Template ID Auto Increment" />
1616
<column xsi:type="varchar" name="name" length="1024" nullable="false" comment="Template Name" />
1717
<column xsi:type="varchar" name="preview_image" nullable="true" length="1024" comment="Template Preview Image"/>
18-
<column xsi:type="text" name="template" nullable="false" comment="Master Format HTML"/>
18+
<column xsi:type="longtext" name="template" nullable="false" comment="Master Format HTML"/>
1919
<column xsi:type="varchar" name="created_for" length="255" nullable="true" comment="Created For" />
2020
<column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP"
2121
comment="Creation Time"/>

app/code/Magento/PageBuilder/view/adminhtml/web/js/template-manager.js

Lines changed: 34 additions & 31 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/template-manager.ts

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ export function saveAsTemplate(stage: Stage) {
5959
*/
6060
confirm(name: string, createdFor: string) {
6161
return new Promise((resolve, reject) => {
62-
// Retrieve the rendering lock from the stage
62+
// Wait for the screenshot and the rendering lock to complete before making the request
6363
const renderingLock = stage.renderingLocks[stage.renderingLocks.length - 1];
6464

65-
// Wait for the screenshot and the rendering lock to complete before making the request
6665
$.when(capture, renderingLock).then((imageSrc: string, content: string) => {
6766
$.ajax({
6867
url: Config.getConfig("template_save_url"),
@@ -134,43 +133,48 @@ function createCapture(stage: Stage) {
134133
const stageElement = document.querySelector("#" + stage.id) as HTMLElement;
135134
const deferred = $.Deferred();
136135

137-
// Resolve issues with Parallax
138-
const parallaxRestore = disableParallax(stageElement);
139-
140-
stageElement.style.height = $(stageElement).outerHeight(false) + "px";
141-
stageElement.classList.add("capture");
142-
stageElement.classList.add("interacting");
136+
// Wait for the stage to complete rendering before taking the capture
137+
const renderingLock = stage.renderingLocks[stage.renderingLocks.length - 1];
138+
renderingLock.then(() => {
139+
// Resolve issues with Parallax
140+
const parallaxRestore = disableParallax(stageElement);
141+
142+
stageElement.style.height = $(stageElement).outerHeight(false) + "px";
143+
stageElement.classList.add("capture");
144+
stageElement.classList.add("interacting");
145+
146+
if (stage.pageBuilder.isFullScreen()) {
147+
window.scrollTo({
148+
top: 0,
149+
});
150+
}
151+
152+
_.defer(() => {
153+
html2canvas(
154+
document.querySelector("#" + stage.id + " .pagebuilder-canvas"),
155+
{
156+
scale: 1,
157+
useCORS: true,
158+
scrollY: (window.pageYOffset * -1),
159+
},
160+
).then((canvas: HTMLCanvasElement) => {
161+
const imageSrc = canvas.toDataURL("image/jpeg", 0.85);
162+
163+
deferred.resolve(imageSrc);
164+
165+
if (stage.pageBuilder.isFullScreen()) {
166+
window.scrollTo({
167+
top: scrollY,
168+
});
169+
}
143170

144-
if (stage.pageBuilder.isFullScreen()) {
145-
window.scrollTo({
146-
top: 0,
171+
stageElement.style.height = null;
172+
stageElement.classList.remove("capture");
173+
stageElement.classList.remove("interacting");
174+
restoreParallax(parallaxRestore);
175+
});
147176
});
148-
}
149177

150-
_.defer(() => {
151-
html2canvas(
152-
document.querySelector("#" + stage.id + " .pagebuilder-canvas"),
153-
{
154-
scale: 1,
155-
useCORS: true,
156-
scrollY: (window.pageYOffset * -1),
157-
},
158-
).then((canvas: HTMLCanvasElement) => {
159-
const imageSrc = canvas.toDataURL("image/jpeg", 0.85);
160-
161-
deferred.resolve(imageSrc);
162-
163-
if (stage.pageBuilder.isFullScreen()) {
164-
window.scrollTo({
165-
top: scrollY,
166-
});
167-
}
168-
169-
stageElement.style.height = null;
170-
stageElement.classList.remove("capture");
171-
stageElement.classList.remove("interacting");
172-
restoreParallax(parallaxRestore);
173-
});
174178
});
175179

176180
return deferred;

0 commit comments

Comments
 (0)