Skip to content

Commit 3dffdfe

Browse files
committed
ACP2E-4058: Not minified JS sometimes loads ignoring 'enable js minifications'
1 parent a947b30 commit 3dffdfe

File tree

5 files changed

+157
-18
lines changed

5 files changed

+157
-18
lines changed

app/code/Magento/Deploy/Service/DeployRequireJsConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function deploy($areaCode, $themePath, $localeCode)
110110
]
111111
);
112112

113-
$fileManager->createRequireJsConfigAsset();
113+
$fileManager->createRequireJsConfigAsset();//see here
114114

115115
$fileManager->createMinResolverAsset();
116116

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright 2025 Adobe
3+
* All Rights Reserved.
4+
*/
5+
6+
var config = {
7+
map: {
8+
'*': {
9+
'rowBuilder': 'Magento_Theme/js/row-builder',
10+
'toggleAdvanced': 'mage/toggle',
11+
'translateInline': 'mage/translate-inline',
12+
'sticky': 'mage/sticky',
13+
'tabs': 'mage/tabs',
14+
'collapsible': 'mage/collapsible',
15+
'dropdownDialog': 'mage/dropdown',
16+
'dropdown': 'mage/dropdowns',
17+
'accordion': 'mage/accordion',
18+
'loader': 'mage/loader',
19+
'tooltip': 'mage/tooltip',
20+
'deletableItem': 'mage/deletable-item',
21+
'itemTable': 'mage/item-table',
22+
'fieldsetControls': 'mage/fieldset-controls',
23+
'fieldsetResetControl': 'mage/fieldset-controls',
24+
'redirectUrl': 'mage/redirect-url',
25+
'loaderAjax': 'mage/loader',
26+
'menu': 'mage/menu',
27+
'popupWindow': 'mage/popup-window',
28+
'validation': 'mage/validation/validation',
29+
'breadcrumbs': 'Magento_Theme/js/view/breadcrumbs',
30+
'jquery/ui': 'jquery/compat',
31+
'cookieStatus': 'Magento_Theme/js/cookie-status',
32+
//'mage/common': 'mage/common.min',
33+
}
34+
},
35+
deps: [
36+
'jquery',
37+
'mage/common',
38+
'mage/dataPost',
39+
'mage/bootstrap'
40+
],
41+
config: {
42+
mixins: {
43+
'Magento_Theme/js/view/breadcrumbs': {
44+
'Magento_Theme/js/view/add-home-breadcrumb': true
45+
}
46+
}
47+
},
48+
/* shim: {
49+
'jquery': {
50+
exports: '$'
51+
}
52+
}*/
53+
};
54+
/*require(['jquery'], function($) {
55+
'use strict';
56+
$.noConflict();
57+
});*/
58+
//require.config(config);
59+
/* eslint-disable max-depth */
60+
/**
61+
* Adds polyfills only for browser contexts which prevents bundlers from including them.
62+
*/
63+
if (typeof window !== 'undefined' && window.document) {
64+
/**
65+
* Polyfill localStorage and sessionStorage for browsers that do not support them.
66+
*/
67+
try {
68+
if (!window.localStorage || !window.sessionStorage) {
69+
throw new Error();
70+
}
71+
72+
localStorage.setItem('storage_test', 1);
73+
localStorage.removeItem('storage_test');
74+
} catch (e) {
75+
config.deps.push('mage/polyfill');
76+
}
77+
}
78+
/* eslint-enable max-depth */

lib/internal/Magento/Framework/RequireJs/Config.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Framework\RequireJs;
77

@@ -20,27 +20,32 @@ class Config
2020
*
2121
* @deprecated since 2.2.0 RequireJS Configuration file is moved into package directory
2222
*/
23-
const DIR_NAME = '_requirejs';
23+
public const DIR_NAME = '_requirejs';
2424

2525
/**
2626
* File name of RequireJs config
2727
*/
28-
const CONFIG_FILE_NAME = 'requirejs-config.js';
28+
public const CONFIG_FILE_NAME = 'requirejs-config.js';
29+
30+
/**
31+
* File name of minified RequireJs config
32+
*/
33+
public const CONFIG_FILE_NAME_MIN = 'requirejs-config-minify.js';
2934

3035
/**
3136
* File name of RequireJs mixins
3237
*/
33-
const MIXINS_FILE_NAME = 'mage/requirejs/mixins.js';
38+
public const MIXINS_FILE_NAME = 'mage/requirejs/mixins.js';
3439

3540
/**
3641
* File name of RequireJs
3742
*/
38-
const REQUIRE_JS_FILE_NAME = 'requirejs/require.js';
43+
public const REQUIRE_JS_FILE_NAME = 'requirejs/require.js';
3944

4045
/**
4146
* File name of StaticJs
4247
*/
43-
const STATIC_FILE_NAME = 'mage/requirejs/static.js';
48+
public const STATIC_FILE_NAME = 'mage/requirejs/static.js';
4449

4550
/**
4651
* File name of minified files resolver
@@ -155,7 +160,7 @@ public function getConfig()
155160
{
156161
$distributedConfig = '';
157162
$customConfigFiles = $this->fileSource->getFiles($this->design->getDesignTheme(), self::CONFIG_FILE_NAME);
158-
163+
159164
foreach ($customConfigFiles as $file) {
160165
/** @var $fileReader \Magento\Framework\Filesystem\File\Read */
161166
$fileReader = $this->readFactory->create($file->getFilename(), DriverPool::FILE);

lib/internal/Magento/Framework/RequireJs/Config/File/Collector/Aggregated.php

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Framework\RequireJs\Config\File\Collector;
88

99
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Filesystem;
11+
use Magento\Framework\RequireJs\Config as RequireJsConfig;
12+
use Magento\Framework\View\Asset\Minification;
1013
use Magento\Framework\View\Design\ThemeInterface;
1114
use Magento\Framework\View\File\CollectorInterface;
15+
use Magento\Framework\View\File\Factory;
1216

1317
/**
1418
* Source of RequireJs config files basing on list of directories they may be located in
@@ -42,29 +46,37 @@ class Aggregated implements CollectorInterface
4246
protected $libDirectory;
4347

4448
/**
45-
* @var \Magento\Framework\View\File\Factory
49+
* @var Factory
4650
*/
4751
protected $fileFactory;
4852

4953
/**
50-
* @param \Magento\Framework\Filesystem $filesystem
51-
* @param \Magento\Framework\View\File\Factory $fileFactory
54+
* @var Minification
55+
*/
56+
private Minification $minification;
57+
58+
/**
59+
* @param Filesystem $filesystem
60+
* @param Factory $fileFactory
5261
* @param CollectorInterface $baseFiles
5362
* @param CollectorInterface $themeFiles
5463
* @param CollectorInterface $themeModularFiles
64+
* @param Minification $minification
5565
*/
5666
public function __construct(
57-
\Magento\Framework\Filesystem $filesystem,
58-
\Magento\Framework\View\File\Factory $fileFactory,
67+
Filesystem $filesystem,
68+
Factory $fileFactory,
5969
CollectorInterface $baseFiles,
6070
CollectorInterface $themeFiles,
61-
CollectorInterface $themeModularFiles
71+
CollectorInterface $themeModularFiles,
72+
Minification $minification
6273
) {
6374
$this->libDirectory = $filesystem->getDirectoryRead(DirectoryList::LIB_WEB);
6475
$this->fileFactory = $fileFactory;
6576
$this->baseFiles = $baseFiles;
6677
$this->themeFiles = $themeFiles;
6778
$this->themeModularFiles = $themeModularFiles;
79+
$this->minification = $minification;
6880
}
6981

7082
/**
@@ -92,6 +104,47 @@ public function getFiles(ThemeInterface $theme, $filePath)
92104
$files = array_merge($files, $this->themeModularFiles->getFiles($currentTheme, $filePath));
93105
$files = array_merge($files, $this->themeFiles->getFiles($currentTheme, $filePath));
94106
}
107+
//return $files;
108+
return $this->adjustMinification($theme, $files, $filePath);
109+
}
110+
111+
/**
112+
* @param ThemeInterface $theme
113+
* @param array $files
114+
* @param string $filePath
115+
* @return array
116+
*/
117+
private function adjustMinification(ThemeInterface $theme, array $files, string $filePath): array
118+
{
119+
if ($this->minification->isEnabled('js') && $filePath === RequireJsConfig::CONFIG_FILE_NAME) {
120+
$minifiedConfigurations = $this->baseFiles->getFiles($theme, RequireJsConfig::CONFIG_FILE_NAME_MIN);
121+
foreach ($theme->getInheritedThemes() as $currentTheme) {
122+
$minifiedConfigurations = array_merge(
123+
$minifiedConfigurations,
124+
$this->themeModularFiles->getFiles($currentTheme, RequireJsConfig::CONFIG_FILE_NAME_MIN)
125+
);
126+
$minifiedConfigurations = array_merge(
127+
$minifiedConfigurations,
128+
$this->themeFiles->getFiles($currentTheme, RequireJsConfig::CONFIG_FILE_NAME_MIN)
129+
);
130+
}
131+
if (!empty($minifiedConfigurations)) {
132+
/* @var \Magento\Framework\View\File $file */
133+
foreach ($files as $key => $file) {
134+
foreach ($minifiedConfigurations as $minifiedConfiguration) {
135+
$replacedFilename = str_replace(
136+
RequireJsConfig::CONFIG_FILE_NAME_MIN,
137+
RequireJsConfig::CONFIG_FILE_NAME,
138+
$minifiedConfiguration->getFilename()
139+
);
140+
if ($file->getFilename() === $replacedFilename) {
141+
$files[$key] = $minifiedConfiguration;
142+
}
143+
}
144+
}
145+
}
146+
}
147+
95148
return $files;
96149
}
97150
}

lib/web/mage/requirejs/mixins.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ define('mixins', [
1717
paths: defaultConfig.paths,
1818
shim: defaultConfig.shim,
1919
config: defaultConfig.config,
20-
map: defaultConfig.map
20+
map: defaultConfig.map,
21+
nameToUrl: defaultConfig.nameToUrl,
2122
},
2223
rjsMixins;
2324

@@ -222,6 +223,8 @@ require([
222223
return originalContextRequire(deps, callback, errback);
223224
};
224225

226+
unbundledContext.nameToUrl = defContext.nameToUrl;
227+
225228
/**
226229
* Wrap original context configuration to update unbundled context,
227230
* that way it is able to respect any changes done after mixins module has initialized.

0 commit comments

Comments
 (0)