From feb680bb26f5b0cefc27ce807dc60a4c82bb7235 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 17 May 2023 11:30:22 -0400 Subject: [PATCH] [AssetMapper] Fix bug where dependencies were preloaded even if the parent was not --- .../Component/AssetMapper/ImportMap/ImportMapManager.php | 4 ++-- .../AssetMapper/Tests/ImportMap/ImportMapManagerTest.php | 3 ++- .../AssetMapper/Tests/fixtures/importmaps/assets2/app2.js | 2 ++ .../AssetMapper/Tests/fixtures/importmaps/assets2/imported.js | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 src/Symfony/Component/AssetMapper/Tests/fixtures/importmaps/assets2/imported.js diff --git a/src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php b/src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php index c35d60d5768ba..15c76054fb485 100644 --- a/src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php +++ b/src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php @@ -417,11 +417,11 @@ private function convertEntriesToImports(array $entries): array $this->modulesToPreload[] = $path; } - $dependencyImportMapEntries = array_map(function (AssetDependency $dependency) { + $dependencyImportMapEntries = array_map(function (AssetDependency $dependency) use ($entryOptions) { return new ImportMapEntry( $dependency->asset->getPublicPathWithoutDigest(), $dependency->asset->getLogicalPath(), - preload: !$dependency->isLazy, + preload: $entryOptions->preload && !$dependency->isLazy, ); }, $dependencies); $imports = array_merge($imports, $this->convertEntriesToImports($dependencyImportMapEntries)); diff --git a/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php b/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php index 0558589a31076..55358553430c3 100644 --- a/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php +++ b/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php @@ -77,7 +77,8 @@ public function testGetImportMapJson() '/assets/pizza/index.js' => '/assets/pizza/index-b3fb5ee31adaf5e1b32d28edf1ab8e7a.js', '/assets/popcorn.js' => '/assets/popcorn-c0778b84ef9893592385aebc95a2896e.js', '/assets/imported_async.js' => '/assets/imported_async-8f0cd418bfeb0cf63826e09a4474a81c.js', - 'other_app' => '/assets/namespaced_assets2/app2-344d0d513d424647e7d8a394ffe5e4b5.js', + 'other_app' => '/assets/namespaced_assets2/app2-d5bf10c20bf9a0b77e67d78fcac301c5.js', + '/assets/namespaced_assets2/imported.js' => '/assets/namespaced_assets2/imported-9ab37dabcfe317fba77123a4e573d53b.js', ]], json_decode($manager->getImportMapJson(), true)); } diff --git a/src/Symfony/Component/AssetMapper/Tests/fixtures/importmaps/assets2/app2.js b/src/Symfony/Component/AssetMapper/Tests/fixtures/importmaps/assets2/app2.js index b565c50b03ce9..2ca1789763e3b 100644 --- a/src/Symfony/Component/AssetMapper/Tests/fixtures/importmaps/assets2/app2.js +++ b/src/Symfony/Component/AssetMapper/Tests/fixtures/importmaps/assets2/app2.js @@ -1 +1,3 @@ +import './imported.js'; + console.log('app2'); diff --git a/src/Symfony/Component/AssetMapper/Tests/fixtures/importmaps/assets2/imported.js b/src/Symfony/Component/AssetMapper/Tests/fixtures/importmaps/assets2/imported.js new file mode 100644 index 0000000000000..5c296e941b632 --- /dev/null +++ b/src/Symfony/Component/AssetMapper/Tests/fixtures/importmaps/assets2/imported.js @@ -0,0 +1 @@ +console.log('imported.js');