From 7c98558b6ab3b9ae51b282874335049840ddcad8 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Tue, 14 Nov 2017 16:07:48 +0000 Subject: [PATCH] fix neglible race when loading CSS --- src/components/structures/MatrixChat.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 26eed952d8..f287ff27af 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -931,8 +931,15 @@ module.exports = React.createClass({ Tinter.tint(colors[0], colors[1]); }; + // turns out that Firefox preloads the CSS for link elements with + // the disabled attribute, but Chrome doesn't. + let cssLoaded = false; + styleElements[theme].onload = () => { + switchTheme(); + }; + for (let i = 0; i < document.styleSheets.length; i++) { const ss = document.styleSheets[i]; if (ss && ss.href === styleElements[theme].href) { @@ -942,11 +949,8 @@ module.exports = React.createClass({ } if (cssLoaded) { + styleElements[theme].onload = undefined; switchTheme(); - } else { - styleElements[theme].onload = () => { - switchTheme(); - }; } if (theme === 'dark') {