Skip to content

Commit db43c11

Browse files
authored
Merge pull request #4721 from magento-performance/MC-19242
[Performance] Fix missing shims and phtml files with mage-init directives
2 parents b31bb4f + a241517 commit db43c11

File tree

15 files changed

+97
-87
lines changed

15 files changed

+97
-87
lines changed

app/code/Magento/Braintree/view/frontend/templates/paypal/button.phtml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@
1111
$id = $block->getContainerId() . random_int(0, PHP_INT_MAX);
1212

1313
$config = [
14-
'Magento_Braintree/js/paypal/button' => [
15-
'id' => $id,
16-
'clientToken' => $block->getClientToken(),
17-
'displayName' => $block->getMerchantName(),
18-
'actionSuccess' => $block->getActionSuccess(),
19-
'environment' => $block->getEnvironment()
20-
]
14+
'id' => $id,
15+
'clientToken' => $block->getClientToken(),
16+
'displayName' => $block->getMerchantName(),
17+
'actionSuccess' => $block->getActionSuccess(),
18+
'environment' => $block->getEnvironment()
2119
];
22-
2320
?>
24-
<div data-mage-init='<?= /* @noEscape */ json_encode($config); ?>'
21+
<div data-mage-init='{"Magento_Braintree/js/paypal/button":<?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($config) ?>}'
2522
class="paypal checkout paypal-logo braintree-paypal-logo<?= /* @noEscape */ $block->getContainerId(); ?>-container">
2623
<div data-currency="<?= /* @noEscape */ $block->getCurrency(); ?>"
2724
data-locale="<?= /* @noEscape */ $block->getLocale(); ?>"

app/code/Magento/Catalog/view/frontend/templates/product/breadcrumbs.phtml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
$viewModel = $block->getData('viewModel');
99
?>
1010
<div class="breadcrumbs"></div>
11+
<?php
12+
$widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($viewModel->getJsonConfigurationHtmlEscaped());
13+
$widgetOptions = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($widget['breadcrumbs']);
14+
?>
1115
<script type="text/x-magento-init">
12-
{
13-
".breadcrumbs": <?= $viewModel->getJsonConfigurationHtmlEscaped() ?>
16+
{
17+
".breadcrumbs": {
18+
"breadcrumbs": <?= /* @noEscape */ $widgetOptions ?>
1419
}
20+
}
1521
</script>

app/code/Magento/Catalog/view/frontend/templates/product/list/toolbar.phtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
// phpcs:disable PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket
1616
?>
1717
<?php if ($block->getCollection()->getSize()) :?>
18-
<div class="toolbar toolbar-products" data-mage-init='<?= /* @noEscape */ $block->getWidgetOptionsJson() ?>'>
18+
<?php $widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($block->getWidgetOptionsJson());
19+
$widgetOptions = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($widget['productListToolbarForm']);
20+
?>
21+
<div class="toolbar toolbar-products" data-mage-init='{"productListToolbarForm":<?= /* @noEscape */ $widgetOptions ?>}'>
1922
<?php if ($block->isExpanded()) :?>
2023
<?php include ($block->getTemplateFile('Magento_Catalog::product/list/toolbar/viewmode.phtml')) ?>
2124
<?php endif; ?>

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
/** @var \Magento\Customer\Block\CustomerData $block */
88
?>
99
<script type="text/x-magento-init">
10-
<?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode([
11-
'*' => ['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-
?>
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+
}
2021
</script>

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
/* @var $block \Magento\Customer\Block\CustomerScopeData */
88
?>
99
<script type="text/x-magento-init">
10-
<?= /* @noEscape */ $block->encodeConfiguration([
11-
'*' => ['Magento_Customer/js/invalidation-processor' => [
12-
'invalidationRules' => [
13-
'website-rule' => [
14-
'Magento_Customer/js/invalidation-rules/website-rule' => [
15-
'scopeConfig' => [
16-
'websiteId' => $block->getWebsiteId(),
17-
]
18-
]
19-
]
20-
]
21-
]],
22-
]);
23-
?>
10+
{
11+
"*": {
12+
"Magento_Customer/js/invalidation-processor": {
13+
"invalidationRules": {
14+
"website-rule": {
15+
"Magento_Customer/js/invalidation-rules/website-rule": {
16+
"scopeConfig": {
17+
"websiteId": "<?= $block->escapeJs($block->getWebsiteId()) ?>"
18+
}
19+
}
20+
}
21+
}
22+
}
23+
}
24+
}
2425
</script>

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
/** @var \Magento\Customer\Block\SectionConfig $block */
88
?>
99
<script type="text/x-magento-init">
10-
<?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode([
11-
'*' => ['Magento_Customer/js/section-config' => [
12-
'sections' => $block->getSections(),
13-
'clientSideSections' => $block->getClientSideSections(),
14-
'baseUrls' => array_unique([
15-
$block->getUrl(null, ['_secure' => true]),
16-
$block->getUrl(null, ['_secure' => false]),
17-
]),
18-
]],
19-
]);
20-
?>
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+
}
20+
}
21+
}
2122
</script>

app/code/Magento/Msrp/view/base/templates/product/price/msrp.phtml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ $priceElementIdPrefix = $block->getPriceElementIdPrefix() ? $block->getPriceElem
5959

6060
$priceElementId = $priceElementIdPrefix . $productId . $block->getIdSuffix();
6161
$popupId = 'msrp-popup-' . $productId . $block->getRandomString(20);
62-
$data = ['addToCart' => [
62+
$data = [
6363
'origin'=> 'msrp',
6464
'popupId' => '#' . $popupId,
6565
'productName' => $block->escapeJs($block->escapeHtml($product->getName())),
@@ -72,11 +72,11 @@ $priceElementIdPrefix = $block->getPriceElementIdPrefix() ? $block->getPriceElem
7272
'closeButtonId' => '#map-popup-close',
7373
'addToCartUrl' => $addToCartUrl,
7474
'paymentButtons' => '[data-label=or]'
75-
]];
75+
];
7676
if ($block->getRequest()->getFullActionName() === 'catalog_product_view') {
77-
$data['addToCart']['addToCartButton'] = '#product_addtocart_form [type=submit]';
77+
$data['addToCartButton'] = '#product_addtocart_form [type=submit]';
7878
} else {
79-
$data['addToCart']['addToCartButton'] = sprintf(
79+
$data['addToCartButton'] = sprintf(
8080
'form:has(input[type="hidden"][name="product"][value="%s"]) button[type="submit"]',
8181
(int) $productId . ',' .
8282
sprintf(
@@ -91,7 +91,7 @@ $priceElementIdPrefix = $block->getPriceElementIdPrefix() ? $block->getPriceElem
9191
id="<?= /* @noEscape */ ($popupId) ?>"
9292
class="action map-show-info"
9393
<?php //phpcs:disable ?>
94-
data-mage-init='<?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($data) ?>'>
94+
data-mage-init='{"addToCart":<?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($data) ?>}'>
9595
<?php //phpcs:enable ?>
9696
<?= $block->escapeHtml(__('Click for price')) ?>
9797
</a>

app/code/Magento/Paypal/view/frontend/templates/express/in-context/component.phtml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@ use Magento\Paypal\Block\Express\InContext\Minicart\Button;
88
/** @var \Magento\Paypal\Block\Express\InContext\Component $block */
99

1010
$configuration = [
11-
'*' => [
12-
'Magento_Paypal/js/in-context/express-checkout' => [
13-
'id' => Button::PAYPAL_BUTTON_ID,
14-
'path' => $block->getUrl(
15-
'paypal/express/gettoken',
16-
[
17-
'_secure' => $block->getRequest()->isSecure()
18-
]
19-
),
20-
'merchantId' => $block->getMerchantId(),
21-
'button' => $block->isButtonContext(),
22-
'clientConfig' => [
23-
'locale' => $block->getLocale(),
24-
'environment' => $block->getEnvironment(),
25-
'button' => [
26-
Button::PAYPAL_BUTTON_ID,
27-
],
28-
]
11+
'id' => Button::PAYPAL_BUTTON_ID,
12+
'path' => $block->getUrl(
13+
'paypal/express/gettoken',
14+
[
15+
'_secure' => $block->getRequest()->isSecure()
16+
]
17+
),
18+
'merchantId' => $block->getMerchantId(),
19+
'button' => $block->isButtonContext(),
20+
'clientConfig' => [
21+
'locale' => $block->getLocale(),
22+
'environment' => $block->getEnvironment(),
23+
'button' => [
24+
Button::PAYPAL_BUTTON_ID,
2925
]
3026
]
3127
];
3228

3329
?>
3430
<div style="display: none;" id="<?= /* @noEscape */ Button::PAYPAL_BUTTON_ID ?>"></div>
3531
<script type="text/x-magento-init">
36-
<?= /* @noEscape */ json_encode($configuration) ?>
32+
{
33+
"*": {
34+
"Magento_Paypal/js/in-context/express-checkout": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($configuration) ?>
35+
}
36+
}
3737
</script>

app/code/Magento/Paypal/view/frontend/templates/express/in-context/shortcut/button.phtml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
/**
88
* @var \Magento\Paypal\Block\Express\InContext\Minicart\SmartButton $block
99
*/
10+
$widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($block->getJsInitParams());
11+
$widgetConfig = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($widget['Magento_Paypal/js/in-context/button']);
1012
?>
11-
<div data-mage-init='<?= /* @noEscape */ $block->getJsInitParams() ?>'
13+
<div data-mage-init='{"Magento_Paypal/js/in-context/button":<?= /* @noEscape */ $widgetConfig ?>}'
1214
class="paypal checkout paypal-logo <?= $block->escapeHtml($block->getContainerId()) ?>-container">
13-
</div>
15+
</div>

app/code/Magento/Paypal/view/frontend/templates/express/shortcut_button.phtml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
*/
66

77
/**
8-
* @var \Magento\Paypal\Block\Express\Shortcut $block
8+
* @var \Magento\Paypal\Block\Express\InContext\SmartButton $block
99
*/
10+
$widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($block->getJsInitParams());
11+
$widgetConfig = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode(
12+
$widget['Magento_Paypal/js/in-context/product-express-checkout']
13+
);
1014
?>
11-
<div data-mage-init='<?= /* @noEscape */ $block->getJsInitParams() ?>'></div>
15+
<div data-mage-init='{"Magento_Paypal/js/in-context/product-express-checkout":<?= /* @noEscape */ $widgetConfig ?>}'></div>

app/code/Magento/Theme/view/base/requirejs-config.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,14 @@ var config = {
1919
'jquery/hover-intent': ['jquery'],
2020
'mage/adminhtml/backup': ['prototype'],
2121
'mage/captcha': ['prototype'],
22-
'mage/common': ['jquery'],
2322
'mage/new-gallery': ['jquery'],
2423
'mage/webapi': ['jquery'],
2524
'jquery/ui': ['jquery'],
2625
'MutationObserver': ['es6-collections'],
27-
'moment': {
28-
'exports': 'moment'
29-
},
3026
'matchMedia': {
3127
'exports': 'mediaCheck'
3228
},
33-
'jquery/jquery-storageapi': {
34-
'deps': ['jquery/jquery.cookie']
35-
}
29+
'magnifier/magnifier': ['jquery']
3630
},
3731
'paths': {
3832
'jquery/validate': 'jquery/jquery.validate',

app/code/Magento/Theme/view/frontend/requirejs-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var config = {
4444
'Magento_Theme/js/view/breadcrumbs': {
4545
'Magento_Theme/js/view/add-home-breadcrumb': true
4646
},
47-
'jquery/jquery-ui': {
47+
'jquery/ui-modules/dialog': {
4848
'jquery/patches/jquery-ui': true
4949
}
5050
}

app/code/Magento/Theme/view/frontend/templates/html/sections.phtml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010

1111
$group = $block->getGroupName();
1212
$groupCss = $block->getGroupCss();
13-
$groupBehavior = $block->getGroupBehaviour() ? $block->getGroupBehaviour() : '{"tabs":{"openedState":"active"}}';
1413
?>
1514
<?php if ($detailedInfoGroup = $block->getGroupChildNames($group, 'getChildHtml')) :?>
1615
<div class="sections <?= $block->escapeHtmlAttr($groupCss) ?>">
1716
<?php $layout = $block->getLayout(); ?>
1817
<div class="section-items <?= $block->escapeHtmlAttr($groupCss) ?>-items"
19-
data-mage-init='<?= $block->escapeHtmlAttr($groupBehavior) ?>'>
18+
data-mage-init='{"tabs":{"openedState":"active"}}'>
2019
<?php foreach ($detailedInfoGroup as $name) :?>
2120
<?php
2221
$html = $layout->renderElement($name);

0 commit comments

Comments
 (0)