Skip to content

Commit dd10d7c

Browse files
vladitasevilhan007
authored andcommitted
fix: prevent runtime error on malformed custom theme object (#4375)
1 parent 17ab2bd commit dd10d7c

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

packages/base/hash.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lG/1T57aPULqB5ErWOkk2B0Pejk=
1+
lG/1T57aPULqB5ErWOkk2B0Pejk=

packages/base/src/theming/applyTheme.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ const loadThemeBase = async theme => {
1616
return;
1717
}
1818

19-
const cssText = await getThemeProperties(BASE_THEME_PACKAGE, theme);
20-
createOrUpdateStyle(cssText, "data-ui5-theme-properties", BASE_THEME_PACKAGE);
19+
const cssData = await getThemeProperties(BASE_THEME_PACKAGE, theme);
20+
if (cssData) {
21+
createOrUpdateStyle(cssData, "data-ui5-theme-properties", BASE_THEME_PACKAGE);
22+
}
2123
};
2224

2325
const deleteThemeBase = () => {
@@ -31,8 +33,10 @@ const loadComponentPackages = async theme => {
3133
return;
3234
}
3335

34-
const cssText = await getThemeProperties(packageName, theme);
35-
createOrUpdateStyle(cssText, "data-ui5-theme-properties", packageName);
36+
const cssData = await getThemeProperties(packageName, theme);
37+
if (cssData) {
38+
createOrUpdateStyle(cssData, "data-ui5-theme-properties", packageName);
39+
}
3640
});
3741
};
3842

packages/base/src/theming/getThemeDesignerTheme.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const warnings = new Set();
2+
13
const getThemeMetadata = () => {
24
// Check if the class was already applied, most commonly to the link/style tag with the CSS Variables
35
let el = document.querySelector(".sapThemeMetaData-Base-baseLib") || document.querySelector(".sapThemeMetaData-UI5-sap-ui-core");
@@ -7,10 +9,18 @@ const getThemeMetadata = () => {
79

810
el = document.createElement("span");
911
el.style.display = "none";
12+
13+
// Try with sapThemeMetaData-Base-baseLib first
1014
el.classList.add("sapThemeMetaData-Base-baseLib");
11-
el.classList.add("sapThemeMetaData-UI5-sap-ui-core");
1215
document.body.appendChild(el);
13-
const metadata = getComputedStyle(el).backgroundImage;
16+
let metadata = getComputedStyle(el).backgroundImage;
17+
18+
// Try with sapThemeMetaData-UI5-sap-ui-core only if the previous selector was not found
19+
if (metadata === "none") {
20+
el.classList.add("sapThemeMetaData-UI5-sap-ui-core");
21+
metadata = getComputedStyle(el).backgroundImage;
22+
}
23+
1424
document.body.removeChild(el);
1525

1626
return metadata;
@@ -25,14 +35,20 @@ const parseThemeMetadata = metadataString => {
2535
try {
2636
paramsString = decodeURIComponent(paramsString);
2737
} catch (ex) {
28-
console.warn("Malformed theme metadata string, unable to decodeURIComponent"); // eslint-disable-line
38+
if (!warnings.has("decode")) {
39+
console.warn("Malformed theme metadata string, unable to decodeURIComponent"); // eslint-disable-line
40+
warnings.add("decode");
41+
}
2942
return;
3043
}
3144
}
3245
try {
3346
return JSON.parse(paramsString);
3447
} catch (ex) {
35-
console.warn("Malformed theme metadata string, unable to parse JSON"); // eslint-disable-line
48+
if (!warnings.has("parse")) {
49+
console.warn("Malformed theme metadata string, unable to parse JSON"); // eslint-disable-line
50+
warnings.add("parse");
51+
}
3652
}
3753
}
3854
};
@@ -45,7 +61,10 @@ const processThemeMetadata = metadata => {
4561
themeName = metadata.Path.match(/\.([^.]+)\.css_variables$/)[1];
4662
baseThemeName = metadata.Extends[0];
4763
} catch (ex) {
48-
console.warn("Malformed theme metadata Object", metadata); // eslint-disable-line
64+
if (!warnings.has("object")) {
65+
console.warn("Malformed theme metadata Object", metadata); // eslint-disable-line
66+
warnings.add("object");
67+
}
4968
return;
5069
}
5170

packages/icons/hash.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
GEYlbexzLpC077jVvsewU+//GU4=
1+
ioZT+Xb+acqvxGzqsYJu+Y7Jxy4=

0 commit comments

Comments
 (0)