Browse Source

fix: localStorage may be `null` in FF

tophf 4 years ago
parent
commit
22361065a3
1 changed files with 7 additions and 3 deletions
  1. 7 3
      src/common/ui/style/index.js

+ 7 - 3
src/common/ui/style/index.js

@@ -6,9 +6,13 @@ let styleTheme;
 /** @type {CSSMediaRule[]} */
 let darkMediaRules;
 let localStorage = {};
-/* Accessing `localStorage` throws in Private Browsing mode and when DOM storage is disabled.
- * Since it allows object-like access, we'll map it to a variable or use a dummy on exception. */
-try { ({ localStorage } = global); } catch (e) { /* keep the dummy object */ }
+/* Accessing `localStorage` in may throw in Private Browsing mode or if dom.storage is disabled.
+ * Since it allows object-like access, we'll map it to a variable with a fallback to a dummy. */
+try {
+  (localStorage = global.localStorage || {}).foo; // eslint-disable-line babel/no-unused-expressions
+} catch (e) {
+  /* keep the dummy object */
+}
 
 const THEME_KEY = 'editorTheme';
 const UI_THEME_KEY = 'uiTheme';