From e313c1ab7e4494a0cda274f9302c1f578ca91bc9 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 5 Jun 2023 08:48:29 +0300 Subject: [PATCH] fix: Theme injection in Safari with polyfill The polyfill does not support push or splice, see https://github.com/calebdwilliams/construct-style-sheets/issues/124 --- .../resources/META-INF/frontend/theme-util.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/flow-server/src/main/resources/META-INF/frontend/theme-util.js b/flow-server/src/main/resources/META-INF/frontend/theme-util.js index 75a9a6e9a69..ac7b8da4178 100644 --- a/flow-server/src/main/resources/META-INF/frontend/theme-util.js +++ b/flow-server/src/main/resources/META-INF/frontend/theme-util.js @@ -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 {