Skip to content

Commit

Permalink
Merge pull request #360 from UN-OCHA/develop
Browse files Browse the repository at this point in the history
Deploy 18-08-2024
  • Loading branch information
lazysoundsystem authored Aug 28, 2024
2 parents abd3564 + 7dfa1de commit 49a18ff
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions PATCHES/core_js_optimizer.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
diff --git a/core/lib/Drupal/Core/Asset/JsCollectionOptimizerLazy.php b/core/lib/Drupal/Core/Asset/JsCollectionOptimizerLazy.php
index 647a2c36a017f890c0e43bbdb350084989b1a7f1..3912afe5a9feeaae235c640cd89816091c7e97be 100644
--- a/core/lib/Drupal/Core/Asset/JsCollectionOptimizerLazy.php
+++ b/core/lib/Drupal/Core/Asset/JsCollectionOptimizerLazy.php
@@ -155,24 +155,32 @@ public function deleteAll() {
public function optimizeGroup(array $group): string {
$data = '';
$current_license = FALSE;
- foreach ($group['items'] as $js_asset) {
- // Ensure license information is available as a comment after
- // optimization.
- if ($js_asset['license'] !== $current_license) {
- $data .= "/* @license " . $js_asset['license']['name'] . " " . $js_asset['license']['url'] . " */\n";
- }
- $current_license = $js_asset['license'];
- // Optimize this JS file, but only if it's not yet minified.
- if (isset($js_asset['minified']) && $js_asset['minified']) {
- $data .= file_get_contents($js_asset['data']);
- }
- else {
- $data .= $this->optimizer->optimize($js_asset);
+
+ // No preprocessing, single JS asset: just use the existing URI.
+ if ($group['type'] === 'file' && !$group['preprocess']) {
+ $data = file_get_contents($group['items'][0]['data']);
+ }
+ else {
+ foreach ($group['items'] as $js_asset) {
+ // Ensure license information is available as a comment after
+ // optimization.
+ if ($js_asset['license'] !== $current_license) {
+ $data .= "/* @license " . $js_asset['license']['name'] . " " . $js_asset['license']['url'] . " */\n";
+ }
+ $current_license = $js_asset['license'];
+ // Optimize this JS file, but only if it's not yet minified.
+ if (isset($js_asset['minified']) && $js_asset['minified']) {
+ $data .= file_get_contents($js_asset['data']);
+ }
+ else {
+ $data .= $this->optimizer->optimize($js_asset);
+ }
+ // Append a ';' and a newline after each JS file to prevent them from
+ // running together.
+ $data .= ";\n";
}
- // Append a ';' and a newline after each JS file to prevent them from
- // running together.
- $data .= ";\n";
}
+
// Remove unwanted JS code that causes issues.
return $this->optimizer->clean($data);
}
1 change: 1 addition & 0 deletions composer.patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"Cron fails on amazon_ses when not configured": "PATCHES/amazon_ses-3417090-cron-queue-14.patch"
},
"drupal/core": {
"Js optimize error https://www.drupal.org/project/drupal/issues/3416508": "PATCHES/core_js_optimizer.patch",
"Views PHP 8.2 compatibility": "PATCHES/core-views-php-82-compatibility.patch"
},
"drupal/stage_file_proxy": {
Expand Down

0 comments on commit 49a18ff

Please sign in to comment.