Skip to content

Commit a63aaa3

Browse files
author
Oleksandr Gorkun
committed
MC-34764: Fix performance degradation cause by CSP
1 parent 18633d9 commit a63aaa3

File tree

23 files changed

+79
-76
lines changed

23 files changed

+79
-76
lines changed

app/code/Magento/Backend/Block/Widget/Button.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ protected function _beforeToHtml()
162162
{
163163
parent::_beforeToHtml();
164164

165-
$buttonId = 'buttonId' .$this->random->getRandomString(32);
165+
$buttonId = 'buttonId' .$this->random->getRandomString(10);
166166
$this->setData('backend_button_widget_hook_id', $buttonId);
167167

168168
$afterHtml = $this->getAfterHtml();

app/code/Magento/Backend/Block/Widget/Button/SplitButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private function identifyOption(array $option): string
243243
? $this->getId() .'-' .$option['id']
244244
: (isset($option['id_attribute']) ?
245245
$option['id_attribute']
246-
: $this->getId() .'-optId' .$this->random->getRandomString(32));
246+
: $this->getId() .'-optId' .$this->random->getRandomString(10));
247247
}
248248

249249
/**

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Action.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected function _toLinkHtml($action, \Magento\Framework\DataObject $row)
132132
}
133133

134134
if (empty($action['id'])) {
135-
$action['id'] = 'id' .$this->random->getRandomString(32);
135+
$action['id'] = 'id' .$this->random->getRandomString(10);
136136
}
137137
$actionAttributes->setData($action);
138138
$onclick = $actionAttributes->getData('onclick');

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Checkbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function renderHeader()
176176
if ($this->getColumn()->getDisabled()) {
177177
$disabled = ' disabled="disabled"';
178178
}
179-
$id = 'id' .$this->random->getRandomString(32);
179+
$id = 'id' .$this->random->getRandomString(10);
180180
$html = '<th class="data-grid-th data-grid-actions-cell"><input type="checkbox" ';
181181
$html .= 'id="' .$id .'" ';
182182
$html .= 'name="' . $this->getColumn()->getFieldName() . '" ';

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/composite/configure.phtml

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,17 @@
1313
"window.productConfigure && productConfigure.onLoadIFrame()",
1414
'iframe[name=\'product_composite_configure_iframe\']:last-of-type'
1515
) ?>
16-
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
17-
"width:0; height:0; border:0px solid #fff; position:absolute; top:-1000px; left:-1000px",
18-
'iframe[name=\'product_composite_configure_iframe\']:last-of-type'
19-
) ?>
2016

2117
<form action="" method="post" id="product_composite_configure_form" enctype="multipart/form-data"
2218
target="product_composite_configure_iframe" class="product_composite_configure_form">
2319
<div class="entry-edit">
2420
<div id="product_composite_configure_messages" class="product_composite_configure_messages">
2521
<div class="messages"><div class="message message-error error"><div></div></div></div>
2622
</div>
27-
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
28-
'display:none;',
29-
'.product_composite_configure_messages:last-of-type'
30-
) ?>
3123
<div id="product_composite_configure_form_fields" class="content product-composite-configure-inner"></div>
3224
<div id="product_composite_configure_form_additional" class="product_composite_configure_form_additional">
3325
</div>
34-
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
35-
'display:none;',
36-
'.product_composite_configure_form_additional:last-of-type'
37-
) ?>
3826
<div id="product_composite_configure_form_confirmed" class="product_composite_configure_form_confirmed"></div>
39-
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
40-
'display:none;',
41-
'.product_composite_configure_form_confirmed:last-of-type'
42-
) ?>
4327
</div>
4428
<input type="hidden" name="as_js_varname" value="iFrameResponse" />
4529
<input type="hidden" name="form_key" value="<?= $block->escapeHtmlAttr($block->getFormKey()) ?>" />
@@ -51,12 +35,21 @@
5135
) ?>
5236

5337
<div id="product_composite_configure_confirmed" class="product_composite_configure_confirmed"></div>
54-
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
55-
'display:none;',
56-
'.product_composite_configure_confirmed:last-of-type'
57-
) ?>
5838

5939
<?php $scriptString = <<<script
40+
prodCompConfIframe = document.querySelector("iframe[name='product_composite_configure_iframe']:last-of-type");
41+
prodCompConfIframe.style.width = 0;
42+
prodCompConfIframe.style.height = 0;
43+
prodCompConfIframe.style.border = "0px solid #fff";
44+
prodCompConfIframe.style.position = "absolute";
45+
prodCompConfIframe.style.top = "-1000px";
46+
prodCompConfIframe.style.left = "-1000px";
47+
document.querySelector(".product_composite_configure_messages:last-of-type").style.display = "none";
48+
document.querySelector(".product_composite_configure_form_additional:last-of-type").style.display = "none";
49+
document.querySelector(".product_composite_configure_form_confirmed:last-of-type").style.display = "none";
50+
document.querySelector(".product_composite_configure_confirmed:last-of-type").style.display = "none";
51+
document.querySelector(".product-configure-popup:last-of-type").style.display = "none";
52+
6053
require([
6154
"jquery",
6255
"mage/mage"
@@ -69,8 +62,3 @@ script;
6962
?>
7063
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false); ?>
7164
</div>
72-
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
73-
'display:none',
74-
'.product-configure-popup:last-of-type'
75-
) ?>
76-

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ $enableLazyLoadingWithoutBorders = (bool)$block->getVar(
1818
'enable_lazy_loading_for_images_without_borders',
1919
'Magento_Catalog'
2020
);
21+
$width = (int)$block->getWidth();
22+
$padding = $block->getRatio() * 100;
2123
?>
2224
<span class="product-image-container" id="product-image-container-<?= /* @noEscape */ $block->getProductId() ?>">
2325
<span class="product-image-wrapper">
@@ -36,11 +38,10 @@ $enableLazyLoadingWithoutBorders = (bool)$block->getVar(
3638
<?php endif; ?>
3739
alt="<?= $escaper->escapeHtmlAttr($block->getLabel()) ?>"/></span>
3840
</span>
39-
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
40-
'width:' . (int)$block->getWidth() . 'px;',
41-
'#product-image-container-' . $block->getProductId()
42-
) ?>
43-
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
44-
'padding-bottom: '. ($block->getRatio() * 100) . '%;',
45-
'#product-image-container-' . $block->getProductId() . ' span.product-image-wrapper'
46-
) ?>
41+
<?php
42+
$script = <<<SCRIPT
43+
document.querySelector('#product-image-container-{$block->getProductId()}').style.width = '{$width}px';
44+
document.querySelector('#product-image-container-{$block->getProductId()} span.product-image-wrapper').style.paddingBottom = '{$padding}%'
45+
SCRIPT;
46+
echo /* @noEscape */$secureRenderer->renderTag('script', ['type' => 'text/javascript'], $script, false);
47+
?>

app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Region.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
7474
'" class="select required-entry admin__control-select">';
7575
$html .= '<option value="">' . __('Please select') . '</option>';
7676
$html .= '</select>';
77-
$html .= $this->secureRenderer->renderStyleAsTag("display:none", '#region');
7877

79-
$scriptString = "\n";
78+
$scriptString = "\ndocument.querySelector('#$selectId').style.display = 'none';\n";
8079
$scriptString .= 'require(["prototype", "mage/adminhtml/form"], function(){';
8180
$scriptString .= '$("' . $selectId . '").setAttribute("defaultValue", "' . $regionId . '");' . "\n";
8281
$scriptString .= 'new regionUpdater("' .

app/code/Magento/Customer/Block/Adminhtml/Grid/Renderer/Multiaction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function _toLinkHtml($action, \Magento\Framework\DataObject $row)
8585

8686
if (isset($action['process']) && $action['process'] == 'configurable') {
8787
if ($product->canConfigure()) {
88-
$id = 'id' .$this->random->getRandomString(32);
88+
$id = 'id' .$this->random->getRandomString(10);
8989
$onClick = sprintf('return %s.configureItem(%s)', $action['control_object'], $row->getId());
9090
return sprintf(
9191
'<a href="%s" id="%s" class="configure-item-link">%s</a>%s',

app/code/Magento/Customer/view/frontend/templates/account/authentication-popup.phtml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/** @var \Magento\Customer\Block\Account\AuthenticationPopup $block */
88
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
99
?>
10-
<div id="authenticationPopup" data-bind="scope:'authenticationPopup'">
10+
<div id="authenticationPopup" data-bind="scope:'authenticationPopup', style: {display: 'none'}">
1111
<?php $scriptString = 'window.authenticationPopup = ' . /* @noEscape */ $block->getSerializedConfig(); ?>
1212
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false); ?>;
1313
<!-- ko template: getTemplate() --><!-- /ko -->
@@ -24,4 +24,3 @@
2424
}
2525
</script>
2626
</div>
27-
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag('display:none', '#authenticationPopup'); ?>

app/code/Magento/Integration/Block/Adminhtml/Widget/Grid/Column/Renderer/Button.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(
5353
public function render(DataObject $row)
5454
{
5555
$attributes = $this->extractAttributes($row);
56-
$attributes['button-renderer-hook-id'] = 'hook' .$this->random->getRandomString(32);
56+
$attributes['button-renderer-hook-id'] = 'hook' .$this->random->getRandomString(10);
5757

5858
return sprintf('<button %s>%s</button>', $this->renderAttributes($attributes), $this->_getValue($row))
5959
.$this->renderSpecialAttributes($attributes);

0 commit comments

Comments
 (0)