Skip to content

Commit

Permalink
fix: Theme injection in Safari with polyfill
Browse files Browse the repository at this point in the history
The polyfill does not support push or splice, see calebdwilliams/construct-style-sheets#124
  • Loading branch information
Artur- committed Jun 5, 2023
1 parent 21afecd commit e313c1a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions flow-server/src/main/resources/META-INF/frontend/theme-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,24 @@ const createLinkReferences = (css, target) => {
return styleCss;
};

const addAdoptedStyleSafariPolyfill = (sheet, target, first) => {
if (first) {
target.adoptedStyleSheets = [sheet, ...target.adoptedStyleSheets];
} else {
target.adoptedStyleSheets = [...target.adoptedStyleSheets, sheet];
}
return () => {
target.adoptedStyleSheets = target.adoptedStyleSheets.filter((ss) => ss !== sheet);
};
};

const addAdoptedStyle = (cssText, target, first) => {
const sheet = new CSSStyleSheet();
sheet.replaceSync(cssText);
if (!target.adoptedStyleSheets.splice) {
// Safari 15 - 16.3, polyfilled
return addAdoptedStyleSafariPolyfill(sheet, target, first);
}
if (first) {
target.adoptedStyleSheets.splice(0, 0, sheet);
} else {
Expand Down

0 comments on commit e313c1a

Please sign in to comment.