Skip to content

Commit

Permalink
Merge pull request #4721 from magento-performance/MC-19242
Browse files Browse the repository at this point in the history
[Performance] Fix missing shims and phtml files with mage-init directives
  • Loading branch information
vzabaznov authored Sep 3, 2019
2 parents b31bb4f + a241517 commit db43c11
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@
$id = $block->getContainerId() . random_int(0, PHP_INT_MAX);

$config = [
'Magento_Braintree/js/paypal/button' => [
'id' => $id,
'clientToken' => $block->getClientToken(),
'displayName' => $block->getMerchantName(),
'actionSuccess' => $block->getActionSuccess(),
'environment' => $block->getEnvironment()
]
'id' => $id,
'clientToken' => $block->getClientToken(),
'displayName' => $block->getMerchantName(),
'actionSuccess' => $block->getActionSuccess(),
'environment' => $block->getEnvironment()
];

?>
<div data-mage-init='<?= /* @noEscape */ json_encode($config); ?>'
<div data-mage-init='{"Magento_Braintree/js/paypal/button":<?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($config) ?>}'
class="paypal checkout paypal-logo braintree-paypal-logo<?= /* @noEscape */ $block->getContainerId(); ?>-container">
<div data-currency="<?= /* @noEscape */ $block->getCurrency(); ?>"
data-locale="<?= /* @noEscape */ $block->getLocale(); ?>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
$viewModel = $block->getData('viewModel');
?>
<div class="breadcrumbs"></div>
<?php
$widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($viewModel->getJsonConfigurationHtmlEscaped());
$widgetOptions = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($widget['breadcrumbs']);
?>
<script type="text/x-magento-init">
{
".breadcrumbs": <?= $viewModel->getJsonConfigurationHtmlEscaped() ?>
{
".breadcrumbs": {
"breadcrumbs": <?= /* @noEscape */ $widgetOptions ?>
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
// phpcs:disable PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket
?>
<?php if ($block->getCollection()->getSize()) :?>
<div class="toolbar toolbar-products" data-mage-init='<?= /* @noEscape */ $block->getWidgetOptionsJson() ?>'>
<?php $widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($block->getWidgetOptionsJson());
$widgetOptions = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($widget['productListToolbarForm']);
?>
<div class="toolbar toolbar-products" data-mage-init='{"productListToolbarForm":<?= /* @noEscape */ $widgetOptions ?>}'>
<?php if ($block->isExpanded()) :?>
<?php include ($block->getTemplateFile('Magento_Catalog::product/list/toolbar/viewmode.phtml')) ?>
<?php endif; ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
/** @var \Magento\Customer\Block\CustomerData $block */
?>
<script type="text/x-magento-init">
<?= /* @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'),
]],
]);
?>
{
"*": {
"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>
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
/* @var $block \Magento\Customer\Block\CustomerScopeData */
?>
<script type="text/x-magento-init">
<?= /* @noEscape */ $block->encodeConfiguration([
'*' => ['Magento_Customer/js/invalidation-processor' => [
'invalidationRules' => [
'website-rule' => [
'Magento_Customer/js/invalidation-rules/website-rule' => [
'scopeConfig' => [
'websiteId' => $block->getWebsiteId(),
]
]
]
]
]],
]);
?>
{
"*": {
"Magento_Customer/js/invalidation-processor": {
"invalidationRules": {
"website-rule": {
"Magento_Customer/js/invalidation-rules/website-rule": {
"scopeConfig": {
"websiteId": "<?= $block->escapeJs($block->getWebsiteId()) ?>"
}
}
}
}
}
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
/** @var \Magento\Customer\Block\SectionConfig $block */
?>
<script type="text/x-magento-init">
<?= /* @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]),
]),
]],
]);
?>
{
"*": {
"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]),
])) ?>
}
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $priceElementIdPrefix = $block->getPriceElementIdPrefix() ? $block->getPriceElem

$priceElementId = $priceElementIdPrefix . $productId . $block->getIdSuffix();
$popupId = 'msrp-popup-' . $productId . $block->getRandomString(20);
$data = ['addToCart' => [
$data = [
'origin'=> 'msrp',
'popupId' => '#' . $popupId,
'productName' => $block->escapeJs($block->escapeHtml($product->getName())),
Expand All @@ -72,11 +72,11 @@ $priceElementIdPrefix = $block->getPriceElementIdPrefix() ? $block->getPriceElem
'closeButtonId' => '#map-popup-close',
'addToCartUrl' => $addToCartUrl,
'paymentButtons' => '[data-label=or]'
]];
];
if ($block->getRequest()->getFullActionName() === 'catalog_product_view') {
$data['addToCart']['addToCartButton'] = '#product_addtocart_form [type=submit]';
$data['addToCartButton'] = '#product_addtocart_form [type=submit]';
} else {
$data['addToCart']['addToCartButton'] = sprintf(
$data['addToCartButton'] = sprintf(
'form:has(input[type="hidden"][name="product"][value="%s"]) button[type="submit"]',
(int) $productId . ',' .
sprintf(
Expand All @@ -91,7 +91,7 @@ $priceElementIdPrefix = $block->getPriceElementIdPrefix() ? $block->getPriceElem
id="<?= /* @noEscape */ ($popupId) ?>"
class="action map-show-info"
<?php //phpcs:disable ?>
data-mage-init='<?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($data) ?>'>
data-mage-init='{"addToCart":<?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($data) ?>}'>
<?php //phpcs:enable ?>
<?= $block->escapeHtml(__('Click for price')) ?>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ use Magento\Paypal\Block\Express\InContext\Minicart\Button;
/** @var \Magento\Paypal\Block\Express\InContext\Component $block */

$configuration = [
'*' => [
'Magento_Paypal/js/in-context/express-checkout' => [
'id' => Button::PAYPAL_BUTTON_ID,
'path' => $block->getUrl(
'paypal/express/gettoken',
[
'_secure' => $block->getRequest()->isSecure()
]
),
'merchantId' => $block->getMerchantId(),
'button' => $block->isButtonContext(),
'clientConfig' => [
'locale' => $block->getLocale(),
'environment' => $block->getEnvironment(),
'button' => [
Button::PAYPAL_BUTTON_ID,
],
]
'id' => Button::PAYPAL_BUTTON_ID,
'path' => $block->getUrl(
'paypal/express/gettoken',
[
'_secure' => $block->getRequest()->isSecure()
]
),
'merchantId' => $block->getMerchantId(),
'button' => $block->isButtonContext(),
'clientConfig' => [
'locale' => $block->getLocale(),
'environment' => $block->getEnvironment(),
'button' => [
Button::PAYPAL_BUTTON_ID,
]
]
];

?>
<div style="display: none;" id="<?= /* @noEscape */ Button::PAYPAL_BUTTON_ID ?>"></div>
<script type="text/x-magento-init">
<?= /* @noEscape */ json_encode($configuration) ?>
{
"*": {
"Magento_Paypal/js/in-context/express-checkout": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($configuration) ?>
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
/**
* @var \Magento\Paypal\Block\Express\InContext\Minicart\SmartButton $block
*/
$widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($block->getJsInitParams());
$widgetConfig = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($widget['Magento_Paypal/js/in-context/button']);
?>
<div data-mage-init='<?= /* @noEscape */ $block->getJsInitParams() ?>'
<div data-mage-init='{"Magento_Paypal/js/in-context/button":<?= /* @noEscape */ $widgetConfig ?>}'
class="paypal checkout paypal-logo <?= $block->escapeHtml($block->getContainerId()) ?>-container">
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
*/

/**
* @var \Magento\Paypal\Block\Express\Shortcut $block
* @var \Magento\Paypal\Block\Express\InContext\SmartButton $block
*/
$widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($block->getJsInitParams());
$widgetConfig = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode(
$widget['Magento_Paypal/js/in-context/product-express-checkout']
);
?>
<div data-mage-init='<?= /* @noEscape */ $block->getJsInitParams() ?>'></div>
<div data-mage-init='{"Magento_Paypal/js/in-context/product-express-checkout":<?= /* @noEscape */ $widgetConfig ?>}'></div>
8 changes: 1 addition & 7 deletions app/code/Magento/Theme/view/base/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,14 @@ var config = {
'jquery/hover-intent': ['jquery'],
'mage/adminhtml/backup': ['prototype'],
'mage/captcha': ['prototype'],
'mage/common': ['jquery'],
'mage/new-gallery': ['jquery'],
'mage/webapi': ['jquery'],
'jquery/ui': ['jquery'],
'MutationObserver': ['es6-collections'],
'moment': {
'exports': 'moment'
},
'matchMedia': {
'exports': 'mediaCheck'
},
'jquery/jquery-storageapi': {
'deps': ['jquery/jquery.cookie']
}
'magnifier/magnifier': ['jquery']
},
'paths': {
'jquery/validate': 'jquery/jquery.validate',
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Theme/view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var config = {
'Magento_Theme/js/view/breadcrumbs': {
'Magento_Theme/js/view/add-home-breadcrumb': true
},
'jquery/jquery-ui': {
'jquery/ui-modules/dialog': {
'jquery/patches/jquery-ui': true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@

$group = $block->getGroupName();
$groupCss = $block->getGroupCss();
$groupBehavior = $block->getGroupBehaviour() ? $block->getGroupBehaviour() : '{"tabs":{"openedState":"active"}}';
?>
<?php if ($detailedInfoGroup = $block->getGroupChildNames($group, 'getChildHtml')) :?>
<div class="sections <?= $block->escapeHtmlAttr($groupCss) ?>">
<?php $layout = $block->getLayout(); ?>
<div class="section-items <?= $block->escapeHtmlAttr($groupCss) ?>-items"
data-mage-init='<?= $block->escapeHtmlAttr($groupBehavior) ?>'>
data-mage-init='{"tabs":{"openedState":"active"}}'>
<?php foreach ($detailedInfoGroup as $name) :?>
<?php
$html = $layout->renderElement($name);
Expand Down
Loading

2 comments on commit db43c11

@kinjalmehta153
Copy link

Choose a reason for hiding this comment

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

this pr is not getting merge while i m going to upgrade my project with magento 2.4.5 version it gives error is any one help me on this : Applying patches for magento/module-theme
patches/composer/M231/github-pr-4721-theme.diff ([Performance] Fix missing shims and phtml files with mage-init directives (db43c11))
Could not apply patch! Skipping. The error was: Cannot apply patch patches/composer/M231/github-pr-4721-theme.diff

[Exception]
Cannot apply patch [Performance] Fix missing shims and phtml files with mage-init directives (db43c11) (patches/composer/M
231/github-pr-4721-theme.diff)!

@limerizal
Copy link

Choose a reason for hiding this comment

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

this pr is not getting merge while i m going to upgrade my project with magento 2.4.5 version it gives error is any one help me on this : Applying patches for magento/module-theme patches/composer/M231/github-pr-4721-theme.diff ([Performance] Fix missing shims and phtml files with mage-init directives (db43c11)) Could not apply patch! Skipping. The error was: Cannot apply patch patches/composer/M231/github-pr-4721-theme.diff

[Exception] Cannot apply patch [Performance] Fix missing shims and phtml files with mage-init directives (db43c11) (patches/composer/M 231/github-pr-4721-theme.diff)!

i'm having the same problem. have you got any solutions?

Please sign in to comment.