From ba8dcad9d8c7859a725c1d9a1957de6bf30bcc16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anderson=20M=C3=BCller?= Date: Sun, 1 Oct 2023 20:27:18 +0200 Subject: [PATCH] Fix adding the mapped controller asset as dependency --- .../StimulusLoaderJavaScriptCompiler.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/StimulusBundle/src/AssetMapper/StimulusLoaderJavaScriptCompiler.php b/src/StimulusBundle/src/AssetMapper/StimulusLoaderJavaScriptCompiler.php index 2c21e175395..2d096c231e3 100644 --- a/src/StimulusBundle/src/AssetMapper/StimulusLoaderJavaScriptCompiler.php +++ b/src/StimulusBundle/src/AssetMapper/StimulusLoaderJavaScriptCompiler.php @@ -62,11 +62,17 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac * and mark it as a "content" dependency so that this file's contents * will be recalculated when the contents of any controller changes. */ - $asset->addDependency(new AssetDependency( - $mappedControllerAsset->asset, - $mappedControllerAsset->isLazy, - true, - )); + if (class_exists(AssetDependency::class)) { + // Backwards compatibility with Symfony 6.3 + $asset->addDependency(new AssetDependency( + $mappedControllerAsset->asset, + $mappedControllerAsset->isLazy, + true, + )); + } else { + $asset->addDependency($mappedControllerAsset->asset); + } + if ($mappedControllerAsset->isLazy) { $lazyControllers[] = sprintf('%s: () => import(%s)', json_encode($name), json_encode($relativeImportPath, \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES));