From a42040de743c06903ab4813f8555d577d4c594ae Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Wed, 10 Jan 2018 17:08:18 +0100 Subject: [PATCH 1/4] update storage.js so no error when the window is not defined --- remix-lib/src/storage.js | 44 ++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/remix-lib/src/storage.js b/remix-lib/src/storage.js index c43ebd62b5..36deb80bbb 100644 --- a/remix-lib/src/storage.js +++ b/remix-lib/src/storage.js @@ -2,16 +2,22 @@ function Storage (prefix) { this.exists = function (name) { - return this.get(name) !== null + if (typeof window !== 'undefined') { + return this.get(name) !== null + } } this.get = function (name) { - return window.localStorage.getItem(prefix + name) + if (typeof window !== 'undefined') { + return window.localStorage.getItem(prefix + name) + } } this.set = function (name, content) { try { - window.localStorage.setItem(prefix + name, content) + if (typeof window !== 'undefined') { + window.localStorage.setItem(prefix + name, content) + } } catch (exception) { return false } @@ -19,8 +25,10 @@ function Storage (prefix) { } this.remove = function (name) { - window.localStorage.removeItem(prefix + name) - return true + if (typeof window !== 'undefined') { + window.localStorage.removeItem(prefix + name) + return true + } } this.rename = function (originalName, newName) { @@ -34,7 +42,9 @@ function Storage (prefix) { function safeKeys () { // NOTE: this is a workaround for some browsers - return Object.keys(window.localStorage).filter(function (item) { return item !== null && item !== undefined }) + if (typeof window !== 'undefined') { + return Object.keys(window.localStorage).filter(function (item) { return item !== null && item !== undefined }) + } } this.keys = function () { @@ -46,16 +56,20 @@ function Storage (prefix) { } // on startup, upgrade the old storage layout - safeKeys().forEach(function (name) { - if (name.indexOf('sol-cache-file-', 0) === 0) { - var content = window.localStorage.getItem(name) - window.localStorage.setItem(name.replace(/^sol-cache-file-/, 'sol:'), content) - window.localStorage.removeItem(name) - } - }) - + if (typeof window !== 'undefined') { + safeKeys().forEach(function (name) { + if (name.indexOf('sol-cache-file-', 0) === 0) { + var content = window.localStorage.getItem(name) + window.localStorage.setItem(name.replace(/^sol-cache-file-/, 'sol:'), content) + window.localStorage.removeItem(name) + } + }) + } + // remove obsolete key - window.localStorage.removeItem('editor-size-cache') + if (typeof window !== 'undefined') { + window.localStorage.removeItem('editor-size-cache') + } } module.exports = Storage From 4c7c2cacd4d51d4a5ec4a8ad14b7be3728ff4cc0 Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Wed, 10 Jan 2018 17:27:14 +0100 Subject: [PATCH 2/4] update storage.js --- remix-lib/src/storage.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/remix-lib/src/storage.js b/remix-lib/src/storage.js index 36deb80bbb..36feab7e98 100644 --- a/remix-lib/src/storage.js +++ b/remix-lib/src/storage.js @@ -44,6 +44,8 @@ function Storage (prefix) { // NOTE: this is a workaround for some browsers if (typeof window !== 'undefined') { return Object.keys(window.localStorage).filter(function (item) { return item !== null && item !== undefined }) + } else { + return [] } } From f0fdbb44b51e7e3a323358487eb6f9a7f39a865e Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Wed, 10 Jan 2018 17:34:56 +0100 Subject: [PATCH 3/4] update to storage --- remix-lib/src/storage.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/remix-lib/src/storage.js b/remix-lib/src/storage.js index 36feab7e98..976f698769 100644 --- a/remix-lib/src/storage.js +++ b/remix-lib/src/storage.js @@ -28,6 +28,8 @@ function Storage (prefix) { if (typeof window !== 'undefined') { window.localStorage.removeItem(prefix + name) return true + } else { + return true } } From dc1bd9ab95e7e72fb6295138e9bad6823520c6c5 Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Wed, 10 Jan 2018 18:00:19 +0100 Subject: [PATCH 4/4] update to storage --- remix-lib/src/storage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remix-lib/src/storage.js b/remix-lib/src/storage.js index 976f698769..305c8cf9e0 100644 --- a/remix-lib/src/storage.js +++ b/remix-lib/src/storage.js @@ -69,7 +69,7 @@ function Storage (prefix) { } }) } - + // remove obsolete key if (typeof window !== 'undefined') { window.localStorage.removeItem('editor-size-cache')