From 4c14894a0a314d65b7c02860fa809dbae57d563d Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Sun, 7 Jan 2018 20:13:26 +0800 Subject: [PATCH] Correctly clone dynami CSSStyleSheets (Fix #1370) --- src/Clone.js | 9 ++++++++ tests/reftests/dynamicstyle.html | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/reftests/dynamicstyle.html diff --git a/src/Clone.js b/src/Clone.js index 4def893..1de4eb7 100644 --- a/src/Clone.js +++ b/src/Clone.js @@ -229,6 +229,15 @@ export class DocumentCloner { return tempIframe; } + if (node instanceof HTMLStyleElement && node.sheet && node.sheet.cssRules) { + const css = [].slice + .call(node.sheet.cssRules, 0) + .reduce((css, rule) => css + rule.cssText, ''); + const style = node.cloneNode(false); + style.textContent = css; + return style; + } + return node.cloneNode(false); } diff --git a/tests/reftests/dynamicstyle.html b/tests/reftests/dynamicstyle.html new file mode 100644 index 0000000..218a2ca --- /dev/null +++ b/tests/reftests/dynamicstyle.html @@ -0,0 +1,37 @@ + + + + Dynamic style + + + + + + +
Static styles
+
Dynamic styles
+ + +