Skip to content

Commit c86887f

Browse files
vladitasevilhan007
authored andcommitted
chore(framework): Improve behavior with multiple instances of CSSVarsPonyfill (#2420)
1 parent ba17192 commit c86887f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/base/src/theming/CSSVarsPonyfill.js

+20
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,29 @@ let ponyfillTimer;
22

33
const ponyfillNeeded = () => !!window.CSSVarsPonyfill;
44

5+
/**
6+
* Removes the "data-cssvars-group" attribute for all element styles and their respective out nodes.
7+
* CSSVarsPonyfill has internal counters for "group" and "job" and running several instances of the ponyfill may lead to issues, since these counters are not shared
8+
* Therefore we remove them for our "data-ui5-element-styles"
9+
*
10+
* @param rootElement
11+
*/
12+
const cleanPonyfillMetadata = (rootElement = document.head) => {
13+
rootElement.querySelectorAll(`style[data-ui5-element-styles][data-cssvars="src"]`).forEach(tag => {
14+
const group = tag.getAttribute("data-cssvars-group");
15+
tag.removeAttribute("data-cssvars-group");
16+
tag.disabled = false;
17+
const outNode = rootElement.querySelector(`style[data-cssvars="out"][data-cssvars-group="${group}"]`);
18+
if (outNode) {
19+
outNode.removeAttribute("data-cssvars-group");
20+
}
21+
});
22+
};
23+
524
const runPonyfill = () => {
625
ponyfillTimer = undefined;
726

27+
cleanPonyfillMetadata();
828
window.CSSVarsPonyfill.cssVars({
929
rootElement: document.head,
1030
variables: isCompact() ? getCompactModeVars() : {},

0 commit comments

Comments
 (0)