Skip to content

Commit cf19598

Browse files
committed
work
1 parent e5fb4f8 commit cf19598

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

app/code/core/Maho/SpeculationRules/Helper/Data.php

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function isEnabled(int|string|null $store = null): bool
3232
/**
3333
* Get speculation rules configuration
3434
*
35-
* @return array<string, array<int, array{where: array{selector_matches: string}, eagerness: string}>>
35+
* @return array<string, array<int, array{where: array{selector_matches: string|string[]}, eagerness: string}>>
3636
*/
3737
public function getSpeculationRules(int|string|null $store = null): array
3838
{
@@ -56,6 +56,9 @@ public function getSpeculationRules(int|string|null $store = null): array
5656
['eagerness' => 'conservative', 'mode' => 'prerender', 'path' => self::XML_PATH_CONSERVATIVE_PRERENDER_SELECTORS],
5757
];
5858

59+
// Group selectors by mode and eagerness
60+
$groupedSelectors = [];
61+
5962
foreach ($configurations as $config) {
6063
$selectorsConfig = (string) Mage::getStoreConfig($config['path'], $store);
6164

@@ -71,16 +74,40 @@ public function getSpeculationRules(int|string|null $store = null): array
7174
continue;
7275
}
7376

74-
// Create rule for each selector
75-
foreach ($selectors as $selector) {
76-
if (!empty($selector)) {
77-
$rules[$config['mode']][] = [
78-
'where' => [
79-
'selector_matches' => $selector,
80-
],
81-
'eagerness' => $config['eagerness'],
82-
];
83-
}
77+
// Group selectors by mode and eagerness
78+
$key = $config['mode'] . '_' . $config['eagerness'];
79+
if (!isset($groupedSelectors[$key])) {
80+
$groupedSelectors[$key] = [
81+
'mode' => $config['mode'],
82+
'eagerness' => $config['eagerness'],
83+
'selectors' => [],
84+
];
85+
}
86+
87+
$groupedSelectors[$key]['selectors'] = array_merge(
88+
$groupedSelectors[$key]['selectors'],
89+
$selectors
90+
);
91+
}
92+
93+
// Create rules from grouped selectors
94+
foreach ($groupedSelectors as $group) {
95+
if (count($group['selectors']) === 1) {
96+
// Single selector
97+
$rules[$group['mode']][] = [
98+
'where' => [
99+
'selector_matches' => $group['selectors'][0],
100+
],
101+
'eagerness' => $group['eagerness'],
102+
];
103+
} else {
104+
// Multiple selectors - use array
105+
$rules[$group['mode']][] = [
106+
'where' => [
107+
'selector_matches' => $group['selectors'],
108+
],
109+
'eagerness' => $group['eagerness'],
110+
];
84111
}
85112
}
86113

app/code/core/Maho/SpeculationRules/etc/config.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444
<dev>
4545
<speculation_rules>
4646
<enabled>0</enabled>
47-
<eager_prefetch_selectors></eager_prefetch_selectors>
48-
<eager_prerender_selectors></eager_prerender_selectors>
49-
<moderate_prefetch_selectors></moderate_prefetch_selectors>
50-
<moderate_prerender_selectors></moderate_prerender_selectors>
51-
<conservative_prefetch_selectors></conservative_prefetch_selectors>
52-
<conservative_prerender_selectors></conservative_prerender_selectors>
47+
<moderate_prefetch_selectors>a.logo
48+
.nav-primary a
49+
.product-name a
50+
.product-image a
51+
.toolbar .pager a
52+
.footer a</moderate_prefetch_selectors>
5353
</speculation_rules>
5454
</dev>
5555
</default>

0 commit comments

Comments
 (0)