Skip to content

Commit

Permalink
MC-36096: [Cloud] Local cache storage is not retained for the expecte…
Browse files Browse the repository at this point in the history
…d period.
  • Loading branch information
tsviklinskyi committed Jul 31, 2020
1 parent 2aaa969 commit 5983e17
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/code/Magento/Customer/view/frontend/web/js/customer-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ define([
url.setBaseUrl(window.BASE_URL);
options.sectionLoadUrl = url.build('customer/section/load');

storage = $.initNamespaceStorage('mage-cache-storage').localStorage;
storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage;

/**
* @param {Object} invalidateOptions
*/
Expand Down Expand Up @@ -214,11 +211,18 @@ define([
this.reload(sectionConfig.getSectionNames(), true);
$.cookieStorage.set('section_data_clean', '');
}
},

/**
* 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;
},

/**
Expand Down Expand Up @@ -356,6 +360,7 @@ define([
*/
'Magento_Customer/js/customer-data': function (settings) {
options = settings;
customerData.initStorage();
invalidateCacheBySessionTimeOut(settings);
invalidateCacheByCloseCookieSession();
customerData.init();
Expand Down

2 comments on commit 5983e17

@HenKun
Copy link

@HenKun HenKun commented on 5983e17 Nov 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit leads to similar issues as described in #24847
Other modules depending on customer-data may use the module before it is initialized in 'Magento_Customer/js/customer-data': function (settings) {, hence storage is undefined, which was not the case before this commit. This especially occurs if bundeling techniques are used, were x-magento-init scipts are evaluated too late.
In this concrete case it leads to an error in checkout page:

[ERROR] Failed to load the "Magento_Checkout/js/view/form/element/email" component.

This component calls checkoutData.getValidatedEmailValue() which in turn uses customer-data. In this stack later on update is called in customer-data, which tries to call storage.set(sectionName, sectionData);. However, as described, storage is not set yet.

@ihor-sviziev
Copy link
Contributor

@ihor-sviziev ihor-sviziev commented on 5983e17 Jan 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HenKun basically you need to execute the getInitCustomerData method, similar to

customerData.getInitCustomerData().done(function () {
if (cartData().items && cartData().items.length !== 0) {
customerData.reload(['cart'], false);
}
});

And the listed issue will not appear

But! I think that's not a good solution.

I created an issue for fixing such behavior #31920

Please sign in to comment.