Skip to content

Commit fab562f

Browse files
author
Artem Iagovdik
committed
fix: Add element existence check to prevent Page Builder crashes
Encountered a scenario where missing HTML elements in Page Builder caused runtime errors due to direct calls to setAttribute. Added an existence check before setting attributes to avoid breaking the editor. This ensures continued functionality and improves stability by handling cases where elements are not found. Logically, the core should include such checks to enhance resilience and user experience.
1 parent 2b809d4 commit fab562f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/stage-builder.js

+5
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/stage-builder.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ function convertToInlineStyles(document: Document): void {
5858

5959
_.each(viewportStyles, (styles, name: string) => {
6060
_.each(styles, (stylesArray: CSSStyleDeclaration[], selector: string) => {
61-
const element: HTMLElement = document.querySelector(selector);
61+
const element = document.querySelector<HTMLElement>(selector);
62+
63+
if (!element) {
64+
console.error('Element not found for selector: %o. Unable to set attribute: "%s".', selector, `data-${name}-style`);
65+
return;
66+
}
6267

6368
_.each(stylesArray, (style: CSSStyleDeclaration) => {
6469
element.setAttribute(

0 commit comments

Comments
 (0)