Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
d1d6a12
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Apr 8, 2022
1 parent 87f0537 commit b66d5d5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Weavy 10.0.3 (2022-04-08)

* Fixed stylesheet loading in dropin-js when using style-nodes in Firefox and Safari.

# Weavy 10.0.2 (2022-04-06)

* Fixed stylesheet loading error in dropin-js when using CORS.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@weavy/dropin-js",
"version": "10.0.2",
"version": "10.0.3",
"author": "Weavy",
"description": "Javascript library for the Weavy drop-in UI",
"homepage": "https://github.com/weavy/weavy-dropin-js",
Expand Down
25 changes: 21 additions & 4 deletions src/dom-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,34 @@ class WeavyRoot {

#applyStyleSheets() {
let styleSheets = this.#styleSheets.map((styleSheetObj) => styleSheetObj.stylesheet).filter((x) => x);

if (WeavyRoot.supportsConstructableStylesheets) {
this.#weavy.debug("CSS: setting adopted stylesheets", this.dom);
this.dom.adoptedStyleSheets = [...this.dom.adoptedStyleSheets, ...styleSheets];
} else {
this.#weavy.debug("CSS: cloning stylesheets", this.dom);
styleSheets.forEach((styleSheet) => {
if (styleSheet.href && !this.dom.querySelector("style[href='" + styleSheet.href + "']")) {
if (styleSheet.ownerNode) {
this.dom.appendChild(styleSheet.ownerNode.cloneNode(true));
if (styleSheet.ownerNode) {
// Check if stylesheet exists already
let isNewLink = styleSheet.href && !this.dom.querySelector("link[rel='stylesheet'][href='" + styleSheet.href + "']");
let isNewStyle = !styleSheet.href && !Array.from(this.dom.querySelectorAll("style")).filter((existingStyle) => {
try {
let matchLength = existingStyle.cssRules.length === styleSheet.cssRules.length;
let matchFirstRule = !existingStyle.cssRules.length || existingStyle.cssRules[0].cssText === styleSheet.cssRules[0].cssText;
let matchLastRule = !existingStyle.cssRules.length || existingStyle.cssRules[existingStyle.cssRule - 1].cssText === styleSheet.cssRules[existingStyle.cssRule - 1].cssText;
return matchLength && matchFirstRule && matchLastRule;
} catch(e) {
return false;
}
}).length;
if (isNewLink || isNewStyle) {
try {
this.dom.appendChild(styleSheet.ownerNode.cloneNode(true));
} catch(e) {
this.weavy.error("Could not clone stylesheet", e)
}
}
} else {
this.#weavy.warn("Could not add stylesheet: No valid ownerNode");
}
});
}
Expand Down

0 comments on commit b66d5d5

Please sign in to comment.