Skip to content

Commit 3a90950

Browse files
Fixed the issue of mage-cache-storage
1 parent 001e814 commit 3a90950

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,6 @@ define([
3030
url.setBaseUrl(window.BASE_URL);
3131
options.sectionLoadUrl = url.build('customer/section/load');
3232

33-
function initStorage() {
34-
if (options.cookieLifeTime !== 'undefined') {
35-
$.cookieStorage.setConf({
36-
path: '/',
37-
expires: new Date(Date.now() + parseInt(options.cookieLifeTime, 10) * 1000)
38-
});
39-
storage = $.initNamespaceStorage('mage-cache-storage').localStorage;
40-
storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage;
41-
}
42-
}
43-
44-
// Initialize storage with default parameters to prevent JS errors while component still not initialized
45-
initStorage();
46-
4733
/**
4834
* @param {Object} invalidateOptions
4935
*/
@@ -241,7 +227,14 @@ define([
241227
/**
242228
* Storage init
243229
*/
244-
initStorage: initStorage,
230+
initStorage: function () {
231+
$.cookieStorage.setConf({
232+
path: '/',
233+
expires: new Date(Date.now() + parseInt(options.cookieLifeTime, 10) * 1000)
234+
});
235+
storage = $.initNamespaceStorage('mage-cache-storage').localStorage;
236+
storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage;
237+
},
245238

246239
/**
247240
* Retrieve the list of sections that has expired since last page reload.
@@ -269,7 +262,9 @@ define([
269262

270263
// process sections that can expire due to storage information inconsistency
271264
_.each(cookieSectionTimestamps, function (cookieSectionTimestamp, sectionName) {
272-
sectionData = storage.get(sectionName);
265+
if (storage !== undefined) {
266+
sectionData = storage.get(sectionName);
267+
}
273268

274269
if (typeof sectionData === 'undefined' ||
275270
typeof sectionData === 'object' &&
@@ -406,10 +401,6 @@ define([
406401
*/
407402
'Magento_Customer/js/customer-data': function (settings) {
408403
options = settings;
409-
410-
// re-init storage with a new settings
411-
customerData.initStorage();
412-
413404
customerData.initStorage();
414405
invalidateCacheBySessionTimeOut(settings);
415406
invalidateCacheByCloseCookieSession();

0 commit comments

Comments
 (0)