@@ -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
*/
@@ -216,14 +230,7 @@ define([
216
230
/**
217
231
* Storage init
218
232
*/
219
- initStorage : function ( ) {
220
- $ . cookieStorage . setConf ( {
221
- path : '/' ,
222
- expires : new Date ( Date . now ( ) + parseInt ( options . cookieLifeTime , 10 ) * 1000 )
223
- } ) ;
224
- storage = $ . initNamespaceStorage ( 'mage-cache-storage' ) . localStorage ;
225
- storageInvalidation = $ . initNamespaceStorage ( 'mage-cache-storage-section-invalidation' ) . localStorage ;
226
- } ,
233
+ initStorage : initStorage ,
227
234
228
235
/**
229
236
* Retrieve the list of sections that has expired since last page reload.
@@ -363,7 +370,10 @@ define([
363
370
*/
364
371
'Magento_Customer/js/customer-data' : function ( settings ) {
365
372
options = settings ;
373
+
374
+ // re-init storage with a new settings
366
375
customerData . initStorage ( ) ;
376
+
367
377
invalidateCacheBySessionTimeOut ( settings ) ;
368
378
invalidateCacheByCloseCookieSession ( ) ;
369
379
customerData . init ( ) ;
0 commit comments