Skip to content

Commit

Permalink
FF bug workaround enforce style order at window.onload
Browse files Browse the repository at this point in the history
see #461
  • Loading branch information
tophf committed Aug 24, 2018
1 parent 2ac9a9d commit 82e6a5b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions content/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,20 @@
if (!prevExpected) {
return;
}
if (!CHROME && !force && window !== top) {
requestAnimationFrame(() => sortStyleElements({force: true}));
if (!CHROME && !force && document.readyState === 'loading') {
/*
FF bug workaround, see https://github.com/openstyles/stylus/issues/461
First we move the styles after HEAD because some libraries like Modernizr
may add a temporary style element into BODY/HTML and assume it's the last styleSheet
consequently failing to access its cssRules as Firefox P R O T E C C S
style elements added by an extension from being accessed in a page script.
Then we wait for the page to load completely, and rearrange the styles again.
*/
addEventListener('load', () => sortStyleElements({force: true}), {once: true});
prevExpected = {nextElementSibling: document.head};
scheduledSort = true;
return;
}
for (const el of styleElements.values()) {
if (!isMovable(el)) {
Expand Down

0 comments on commit 82e6a5b

Please sign in to comment.