Skip to content

Commit ed6995c

Browse files
MC-4277: Address Product Page slowness due to 'product_data_storage' handling
- add localStorage support check
1 parent 33bda6c commit ed6995c

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

app/code/Magento/Catalog/view/frontend/web/js/product/storage/data-storage.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ define([
3434
};
3535
}
3636

37+
/**
38+
* Set data to localStorage with support check.
39+
*
40+
* @param {String} namespace
41+
* @param {Object} data
42+
*/
43+
function setLocalStorageItem(namespace, data) {
44+
try {
45+
window.localStorage.setItem(namespace, JSON.stringify(data));
46+
} catch (e) {
47+
console.warn('localStorage is unavailable - skipping local caching of product data');
48+
console.error(e);
49+
}
50+
}
51+
3752
return {
3853

3954
/**
@@ -118,7 +133,7 @@ define([
118133
if (_.isEmpty(data)) {
119134
this.localStorage.removeAll();
120135
} else {
121-
window.localStorage.setItem(this.namespace, JSON.stringify(data));
136+
setLocalStorageItem(this.namespace, data);
122137
}
123138
},
124139

app/code/Magento/Catalog/view/frontend/web/js/product/storage/ids-storage.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ define([
1111
], function ($, _, ko, utils) {
1212
'use strict';
1313

14+
/**
15+
* Set data to localStorage with support check.
16+
*
17+
* @param {String} namespace
18+
* @param {Object} data
19+
*/
20+
function setLocalStorageItem(namespace, data) {
21+
try {
22+
window.localStorage.setItem(namespace, JSON.stringify(data));
23+
} catch (e) {
24+
console.warn('localStorage is unavailable - skipping local caching of product data');
25+
console.error(e);
26+
}
27+
}
28+
1429
return {
1530

1631
/**
@@ -94,7 +109,7 @@ define([
94109
* Initializes handler to "data" property update
95110
*/
96111
internalDataHandler: function (data) {
97-
window.localStorage.setItem(this.namespace, JSON.stringify(data));
112+
setLocalStorageItem(this.namespace, data);
98113
},
99114

100115
/**

0 commit comments

Comments
 (0)