@@ -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,22 @@ define([
30
32
url . setBaseUrl ( window . BASE_URL ) ;
31
33
options . sectionLoadUrl = url . build ( 'customer/section/load' ) ;
32
34
35
+ /**
36
+ * Storage initialization
37
+ */
38
+ function initStorage ( ) {
39
+ $ . cookieStorage . setConf ( {
40
+ path : '/' ,
41
+ expires : new Date ( Date . now ( ) + parseInt ( options . cookieLifeTime , 10 ) * 1000 ) ,
42
+ samesite : 'lax'
43
+ } ) ;
44
+ storage = $ . initNamespaceStorage ( 'mage-cache-storage' ) . localStorage ;
45
+ storageInvalidation = $ . initNamespaceStorage ( 'mage-cache-storage-section-invalidation' ) . localStorage ;
46
+ }
47
+
48
+ // Initialize storage with default parameters to prevent JS errors while component still not initialized
49
+ initStorage ( ) ;
50
+
33
51
/**
34
52
* @param {Object } invalidateOptions
35
53
*/
@@ -216,15 +234,7 @@ define([
216
234
/**
217
235
* Storage init
218
236
*/
219
- initStorage : function ( ) {
220
- $ . cookieStorage . setConf ( {
221
- path : '/' ,
222
- expires : new Date ( Date . now ( ) + parseInt ( options . cookieLifeTime , 10 ) * 1000 ) ,
223
- samesite : 'lax'
224
- } ) ;
225
- storage = $ . initNamespaceStorage ( 'mage-cache-storage' ) . localStorage ;
226
- storageInvalidation = $ . initNamespaceStorage ( 'mage-cache-storage-section-invalidation' ) . localStorage ;
227
- } ,
237
+ initStorage : initStorage ,
228
238
229
239
/**
230
240
* Retrieve the list of sections that has expired since last page reload.
@@ -389,7 +399,10 @@ define([
389
399
*/
390
400
'Magento_Customer/js/customer-data' : function ( settings ) {
391
401
options = settings ;
402
+
403
+ // re-init storage with a new settings
392
404
customerData . initStorage ( ) ;
405
+
393
406
invalidateCacheBySessionTimeOut ( settings ) ;
394
407
invalidateCacheByCloseCookieSession ( ) ;
395
408
customerData . init ( ) ;
0 commit comments