Skip to content

Commit 4ff04dc

Browse files
committed
Fix customer data and sections configuration race condition
1 parent 2cc9d29 commit 4ff04dc

File tree

4 files changed

+40
-49
lines changed

4 files changed

+40
-49
lines changed

app/code/Magento/Customer/view/frontend/templates/js/customer-data.phtml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66

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

app/code/Magento/Customer/view/frontend/templates/js/section-config.phtml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@
66

77
/** @var \Magento\Customer\Block\SectionConfig $block */
88
?>
9-
<script type="text/x-magento-init">
10-
{
11-
"*": {
12-
"Magento_Customer/js/section-config": {
13-
"sections": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($block->getSections()) ?>,
14-
"clientSideSections": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($block->getClientSideSections()) ?>,
15-
"baseUrls": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode(array_unique([
16-
$block->getUrl(null, ['_secure' => true]),
17-
$block->getUrl(null, ['_secure' => false]),
18-
])) ?>,
19-
"sectionNames": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)
20-
->jsonEncode($block->getData('sectionNamesProvider')->getSectionNames()) ?>
21-
}
22-
}
23-
}
9+
<script>
10+
requirejs.config({
11+
config: <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode([
12+
'Magento_Customer/js/section-config' => [
13+
'sections' => $block->getSections(),
14+
'clientSideSections' => $block->getClientSideSections(),
15+
'baseUrls' => array_unique([
16+
$block->getUrl(null, ['_secure' => true]),
17+
$block->getUrl(null, ['_secure' => false]),
18+
]),
19+
]
20+
]); ?>
21+
});
2422
</script>

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ define([
1111
'underscore',
1212
'ko',
1313
'Magento_Customer/js/section-config',
14-
'mage/url',
14+
'module',
1515
'mage/storage',
1616
'jquery/jquery-storageapi'
17-
], function ($, _, ko, sectionConfig, url) {
17+
], function ($, _, ko, sectionConfig, module) {
1818
'use strict';
1919

20-
var options = {},
20+
var options = module.config(),
2121
storage,
2222
storageInvalidation,
2323
invalidateCacheBySessionTimeOut,
@@ -26,9 +26,6 @@ define([
2626
buffer,
2727
customerData;
2828

29-
url.setBaseUrl(window.BASE_URL);
30-
options.sectionLoadUrl = url.build('customer/section/load');
31-
3229
//TODO: remove global change, in this case made for initNamespaceStorage
3330
$.cookieStorage.setConf({
3431
path: '/',
@@ -337,17 +334,15 @@ define([
337334
},
338335

339336
/**
340-
* @param {Object} settings
341337
* @constructor
342338
*/
343-
'Magento_Customer/js/customer-data': function (settings) {
344-
options = settings;
345-
invalidateCacheBySessionTimeOut(settings);
346-
invalidateCacheByCloseCookieSession();
347-
customerData.init();
348-
}
339+
'Magento_Customer/js/customer-data': function () {}
349340
};
350341

342+
invalidateCacheBySessionTimeOut(options);
343+
invalidateCacheByCloseCookieSession();
344+
customerData.init();
345+
351346
/**
352347
* Events listener
353348
*/

app/code/Magento/Customer/view/frontend/web/js/section-config.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
* See COPYING.txt for license details.
44
*/
55

6-
define(['underscore'], function (_) {
6+
define(['underscore', 'module'], function (_, module) {
77
'use strict';
88

9-
var baseUrls, sections, clientSideSections, sectionNames, canonize;
9+
var options = module.config(),
10+
baseUrls = options.baseUrls,
11+
sections = options.sections,
12+
clientSideSections = options.clientSideSections,
13+
sectionNames = options.sectionNames,
14+
canonize;
1015

1116
/**
1217
* @param {String} url
@@ -80,14 +85,8 @@ define(['underscore'], function (_) {
8085
},
8186

8287
/**
83-
* @param {Object} options
8488
* @constructor
8589
*/
86-
'Magento_Customer/js/section-config': function (options) {
87-
baseUrls = options.baseUrls;
88-
sections = options.sections;
89-
clientSideSections = options.clientSideSections;
90-
sectionNames = options.sectionNames;
91-
}
90+
'Magento_Customer/js/section-config': function () {}
9291
};
9392
});

0 commit comments

Comments
 (0)