From f407591803b49a7802e24ebcf79a59d21b8c5ccf Mon Sep 17 00:00:00 2001 From: Hugues Tavernier Date: Tue, 11 Jul 2023 13:32:30 +0200 Subject: [PATCH] fix bug manualChunks are not preloaded --- src/Asset/EntrypointRenderer.php | 10 +++++++++- src/Asset/EntrypointsLookup.php | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Asset/EntrypointRenderer.php b/src/Asset/EntrypointRenderer.php index c58f497..950b23f 100644 --- a/src/Asset/EntrypointRenderer.php +++ b/src/Asset/EntrypointRenderer.php @@ -110,7 +110,7 @@ public function renderLinks(string $entryName, array $options = [], $buildName = ], $options['attr'] ?? []), $buildName); } - if ($this->entrypointsLookup->isProd($buildName) && isset($options['preloadDynamicImports']) && true === $options['preloadDynamicImports']) { + if ($this->entrypointsLookup->isProd($buildName)) { foreach ($this->entrypointsLookup->getJavascriptDependencies($entryName, $buildName) as $fileWithHash) { $content[] = $this->tagRenderer->renderLinkPreload($fileWithHash['path'], [ 'integrity' => $fileWithHash['hash'], @@ -118,6 +118,14 @@ public function renderLinks(string $entryName, array $options = [], $buildName = } } + if ($this->entrypointsLookup->isProd($buildName) && isset($options['preloadDynamicImports']) && true === $options['preloadDynamicImports']) { + foreach ($this->entrypointsLookup->getJavascriptDynamicDependencies($entryName, $buildName) as $fileWithHash) { + $content[] = $this->tagRenderer->renderLinkPreload($fileWithHash['path'], [ + 'integrity' => $fileWithHash['hash'], + ], $buildName); + } + } + return implode(PHP_EOL, $content); } diff --git a/src/Asset/EntrypointsLookup.php b/src/Asset/EntrypointsLookup.php index 708411f..ec26713 100644 --- a/src/Asset/EntrypointsLookup.php +++ b/src/Asset/EntrypointsLookup.php @@ -94,6 +94,13 @@ public function getJavascriptDependencies($entryName, $buildName = null): array return $this->getInfos($buildName)['entryPoints'][$entryName]['preload'] ?? []; } + public function getJavascriptDynamicDependencies($entryName, $buildName = null): array + { + $this->throwIfEntryIsMissing($entryName, $buildName); + + return $this->getInfos($buildName)['entryPoints'][$entryName]['dynamic'] ?? []; + } + public function hasLegacy($entryName, $buildName = null): bool { $this->throwIfEntryIsMissing($entryName, $buildName);