From d5dfffc90c7c64b1c21f9cd23839e8df49de7e1f Mon Sep 17 00:00:00 2001 From: Aaron S Date: Mon, 9 Jan 2023 09:05:38 -0600 Subject: [PATCH] fix(pubsub): Update localStorage logic to function when cookies are disabled --- packages/pubsub/src/vendor/paho-mqtt.js | 46 ++++++++++++++++--------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/packages/pubsub/src/vendor/paho-mqtt.js b/packages/pubsub/src/vendor/paho-mqtt.js index ffbc4e57bd1..36ff585af7d 100644 --- a/packages/pubsub/src/vendor/paho-mqtt.js +++ b/packages/pubsub/src/vendor/paho-mqtt.js @@ -102,23 +102,35 @@ function onMessageArrived(message) { /** * @private */ - var localStorage = - global.localStorage || - (function () { - var data = {}; - - return { - setItem: function (key, item) { - data[key] = item; - }, - getItem: function (key) { - return data[key]; - }, - removeItem: function (key) { - delete data[key]; - }, - }; - })(); + var localStorage; + try { + } catch (_unused) { + console.log('asd'); + } + + try { + localStorage = global.localStorage; + } catch (e) { + console.log(e); + } finally { + localStorage = + localStorage ?? + (function () { + var data = {}; + + return { + setItem: function (key, item) { + data[key] = item; + }, + getItem: function (key) { + return data[key]; + }, + removeItem: function (key) { + delete data[key]; + }, + }; + })(); + } /** * Unique message type identifiers, with associated