diff --git a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js index 213aa105ba25b..1f580cfccd0b3 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js +++ b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js @@ -17,7 +17,9 @@ define([ ], function ($, _, ko, sectionConfig, url) { 'use strict'; - var options = {}, + var options = { + cookieLifeTime: 86400 //1 day by default + }, storage, storageInvalidation, invalidateCacheBySessionTimeOut, @@ -30,6 +32,18 @@ define([ url.setBaseUrl(window.BASE_URL); options.sectionLoadUrl = url.build('customer/section/load'); + function initStorage() { + $.cookieStorage.setConf({ + path: '/', + expires: new Date(Date.now() + parseInt(options.cookieLifeTime, 10) * 1000) + }); + storage = $.initNamespaceStorage('mage-cache-storage').localStorage; + storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage; + } + + // Initialize storage with default parameters to prevent JS errors while component still not initialized + initStorage(); + /** * @param {Object} invalidateOptions */ @@ -217,14 +231,7 @@ define([ /** * Storage init */ - initStorage: function () { - $.cookieStorage.setConf({ - path: '/', - expires: new Date(Date.now() + parseInt(options.cookieLifeTime, 10) * 1000) - }); - storage = $.initNamespaceStorage('mage-cache-storage').localStorage; - storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage; - }, + initStorage: initStorage, /** * Retrieve the list of sections that has expired since last page reload. @@ -389,6 +396,10 @@ define([ */ 'Magento_Customer/js/customer-data': function (settings) { options = settings; + + // re-init storage with a new settings + customerData.initStorage(); + customerData.initStorage(); invalidateCacheBySessionTimeOut(settings); invalidateCacheByCloseCookieSession();