@@ -17,7 +17,9 @@ define([
17
17
] , function ( $ , _ , ko , sectionConfig , url ) {
18
18
'use strict' ;
19
19
20
- var options = { } ,
20
+ var options = {
21
+ cookieLifeTime : 86400 //1 day by default
22
+ } ,
21
23
storage ,
22
24
storageInvalidation ,
23
25
invalidateCacheBySessionTimeOut ,
@@ -30,6 +32,18 @@ define([
30
32
url . setBaseUrl ( window . BASE_URL ) ;
31
33
options . sectionLoadUrl = url . build ( 'customer/section/load' ) ;
32
34
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
+
33
47
/**
34
48
* @param {Object } invalidateOptions
35
49
*/
@@ -217,14 +231,7 @@ define([
217
231
/**
218
232
* Storage init
219
233
*/
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 ,
228
235
229
236
/**
230
237
* Retrieve the list of sections that has expired since last page reload.
@@ -389,6 +396,10 @@ define([
389
396
*/
390
397
'Magento_Customer/js/customer-data' : function ( settings ) {
391
398
options = settings ;
399
+
400
+ // re-init storage with a new settings
401
+ customerData . initStorage ( ) ;
402
+
392
403
customerData . initStorage ( ) ;
393
404
invalidateCacheBySessionTimeOut ( settings ) ;
394
405
invalidateCacheByCloseCookieSession ( ) ;
0 commit comments