Skip to content

Commit 847c799

Browse files
authored
Revert changes for fixing JS errors in customer data
Revert code changes for fixing errors in customer data when component is not initialized - accident removed in a previous commit
1 parent e0d650c commit 847c799

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ define([
1717
], function ($, _, ko, sectionConfig, url) {
1818
'use strict';
1919

20-
var options = {},
20+
var options = {
21+
cookieLifeTime: 86400 //1 day by default
22+
},
2123
storage,
2224
storageInvalidation,
2325
invalidateCacheBySessionTimeOut,
@@ -30,6 +32,18 @@ define([
3032
url.setBaseUrl(window.BASE_URL);
3133
options.sectionLoadUrl = url.build('customer/section/load');
3234

35+
function initStorage() {
36+
$.cookieStorage.setConf({
37+
path: '/',
38+
expires: new Date(Date.now() + parseInt(options.cookieLifeTime, 10) * 1000)
39+
});
40+
storage = $.initNamespaceStorage('mage-cache-storage').localStorage;
41+
storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage;
42+
}
43+
44+
// Initialize storage with default parameters to prevent JS errors while component still not initialized
45+
initStorage();
46+
3347
/**
3448
* @param {Object} invalidateOptions
3549
*/
@@ -217,14 +231,7 @@ define([
217231
/**
218232
* Storage init
219233
*/
220-
initStorage: function () {
221-
$.cookieStorage.setConf({
222-
path: '/',
223-
expires: new Date(Date.now() + parseInt(options.cookieLifeTime, 10) * 1000)
224-
});
225-
storage = $.initNamespaceStorage('mage-cache-storage').localStorage;
226-
storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage;
227-
},
234+
initStorage: initStorage,
228235

229236
/**
230237
* Retrieve the list of sections that has expired since last page reload.
@@ -389,6 +396,10 @@ define([
389396
*/
390397
'Magento_Customer/js/customer-data': function (settings) {
391398
options = settings;
399+
400+
// re-init storage with a new settings
401+
customerData.initStorage();
402+
392403
customerData.initStorage();
393404
invalidateCacheBySessionTimeOut(settings);
394405
invalidateCacheByCloseCookieSession();

0 commit comments

Comments
 (0)