Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix customer data and sections configuration race condition #24847

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@

/** @var \Magento\Customer\Block\CustomerData $block */
?>
<script type="text/x-magento-init">
{
"*": {
"Magento_Customer/js/customer-data": {
"sectionLoadUrl": "<?= $block->escapeJs($block->escapeUrl($block->getCustomerDataUrl('customer/section/load'))) ?>",
"expirableSectionLifetime": <?= (int)$block->getExpirableSectionLifetime() ?>,
"expirableSectionNames": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($block->getExpirableSectionNames()) ?>,
"cookieLifeTime": "<?= $block->escapeJs($block->getCookieLifeTime()) ?>",
"updateSessionUrl": "<?= $block->escapeJs($block->escapeUrl($block->getCustomerDataUrl('customer/account/updateSession'))) ?>"
}
}
}
<script>
requirejs.config({
config: <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode(['Magento_Customer/js/customer-data' => [
'sectionLoadUrl' => $block->getCustomerDataUrl('customer/section/load'),
'expirableSectionLifetime' => $block->getExpirableSectionLifetime(),
'expirableSectionNames' => $block->getExpirableSectionNames(),
'cookieLifeTime' => $block->getCookieLifeTime(),
'updateSessionUrl' => $block->getCustomerDataUrl('customer/account/updateSession'),
]]); ?>

});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@

/** @var \Magento\Customer\Block\SectionConfig $block */
?>
<script type="text/x-magento-init">
{
"*": {
"Magento_Customer/js/section-config": {
"sections": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($block->getSections()) ?>,
"clientSideSections": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($block->getClientSideSections()) ?>,
"baseUrls": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode(array_unique([
$block->getUrl(null, ['_secure' => true]),
$block->getUrl(null, ['_secure' => false]),
])) ?>,
"sectionNames": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)
->jsonEncode($block->getData('sectionNamesProvider')->getSectionNames()) ?>
}
}
}
<script>
requirejs.config({
config: <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode([
'Magento_Customer/js/section-config' => [
'sections' => $block->getSections(),
'clientSideSections' => $block->getClientSideSections(),
'baseUrls' => array_unique([
$block->getUrl(null, ['_secure' => true]),
$block->getUrl(null, ['_secure' => false]),
]),
'sectionNames' => $block->getData('sectionNamesProvider')->getSectionNames()
]
]); ?>
});
</script>
21 changes: 8 additions & 13 deletions app/code/Magento/Customer/view/frontend/web/js/customer-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ define([
'underscore',
'ko',
'Magento_Customer/js/section-config',
'mage/url',
'module',
'mage/storage',
'jquery/jquery-storageapi'
], function ($, _, ko, sectionConfig, url) {
], function ($, _, ko, sectionConfig, module) {
'use strict';

var options = {},
var options = module.config(),
storage,
storageInvalidation,
invalidateCacheBySessionTimeOut,
Expand All @@ -26,9 +26,6 @@ define([
buffer,
customerData;

url.setBaseUrl(window.BASE_URL);
options.sectionLoadUrl = url.build('customer/section/load');

//TODO: remove global change, in this case made for initNamespaceStorage
$.cookieStorage.setConf({
path: '/',
Expand Down Expand Up @@ -337,17 +334,15 @@ define([
},

/**
* @param {Object} settings
* @constructor
*/
'Magento_Customer/js/customer-data': function (settings) {
options = settings;
invalidateCacheBySessionTimeOut(settings);
invalidateCacheByCloseCookieSession();
customerData.init();
}
'Magento_Customer/js/customer-data': function () {}
};

invalidateCacheBySessionTimeOut(options);
invalidateCacheByCloseCookieSession();
customerData.init();

/**
* Events listener
*/
Expand Down
17 changes: 8 additions & 9 deletions app/code/Magento/Customer/view/frontend/web/js/section-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
* See COPYING.txt for license details.
*/

define(['underscore'], function (_) {
define(['underscore', 'module'], function (_, module) {
'use strict';

var baseUrls, sections, clientSideSections, sectionNames, canonize;
var options = module.config(),
baseUrls = options.baseUrls,
sections = options.sections,
clientSideSections = options.clientSideSections,
sectionNames = options.sectionNames,
canonize;

/**
* @param {String} url
Expand Down Expand Up @@ -80,14 +85,8 @@ define(['underscore'], function (_) {
},

/**
* @param {Object} options
* @constructor
*/
'Magento_Customer/js/section-config': function (options) {
baseUrls = options.baseUrls;
sections = options.sections;
clientSideSections = options.clientSideSections;
sectionNames = options.sectionNames;
}
'Magento_Customer/js/section-config': function () {}
};
});