From 1a7c800bd1ed96876e64079800835cb17777cd10 Mon Sep 17 00:00:00 2001 From: Hugues Tavernier Date: Fri, 6 Oct 2023 12:48:24 +0200 Subject: [PATCH] no duplicate modulepreload for javascriptDependencies --- src/Asset/EntrypointRenderer.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Asset/EntrypointRenderer.php b/src/Asset/EntrypointRenderer.php index 2ed64c6..d398324 100644 --- a/src/Asset/EntrypointRenderer.php +++ b/src/Asset/EntrypointRenderer.php @@ -2,8 +2,6 @@ namespace Pentatrion\ViteBundle\Asset; -use function in_array; - class EntrypointRenderer { private $entrypointsLookup; @@ -115,15 +113,17 @@ public function renderLinks(string $entryName, array $options = [], $buildName = if ($this->entrypointsLookup->isProd($buildName)) { foreach ($this->entrypointsLookup->getJavascriptDependencies($entryName, $buildName) as $fileWithHash) { - $content[] = $this->tagRenderer->renderLinkPreload($fileWithHash['path'], [ - 'integrity' => $fileWithHash['hash'], - ], $buildName); + if (false === \in_array($fileWithHash['path'], $this->returnedPreloadedScripts, true)) { + $content[] = $this->tagRenderer->renderLinkPreload($fileWithHash['path'], [ + 'integrity' => $fileWithHash['hash'], + ], $buildName); + } } } if ($this->entrypointsLookup->isProd($buildName) && isset($options['preloadDynamicImports']) && true === $options['preloadDynamicImports']) { foreach ($this->entrypointsLookup->getJavascriptDynamicDependencies($entryName, $buildName) as $fileWithHash) { - if (in_array($fileWithHash['path'], $this->returnedPreloadedScripts, true) === false) { + if (false === \in_array($fileWithHash['path'], $this->returnedPreloadedScripts, true)) { $content[] = $this->tagRenderer->renderLinkPreload($fileWithHash['path'], [ 'integrity' => $fileWithHash['hash'], ], $buildName);