From 7a73698b709c9655acacb7a8b3960f2a2bf50972 Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Tue, 3 Sep 2024 14:49:58 +0300 Subject: [PATCH] fix: No react module for Vaadin Router Remove reactOutlet module if we are not running react, but are using Vaadin Router inferred from index.ts Fixes #19870 --- .../scanner/FrontendDependenciesScanner.java | 3 +- .../scanner/FullDependenciesScanner.java | 29 +++++++++++++++++-- .../scanner/FullDependenciesScannerTest.java | 7 +++-- .../frontend/scanner/FullScannerPwaTest.java | 3 +- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/flow-server/src/main/java/com/vaadin/flow/server/frontend/scanner/FrontendDependenciesScanner.java b/flow-server/src/main/java/com/vaadin/flow/server/frontend/scanner/FrontendDependenciesScanner.java index 78c74dab733..ce929c9360a 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/frontend/scanner/FrontendDependenciesScanner.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/frontend/scanner/FrontendDependenciesScanner.java @@ -100,7 +100,8 @@ public FrontendDependenciesScanner createScanner( if (allDependenciesScan) { // this dep scanner can't distinguish embeddable web component // frontend related annotations - return new FullDependenciesScanner(finder, featureFlags); + return new FullDependenciesScanner(finder, featureFlags, + reactEnabled); } else { return new FrontendDependencies(finder, generateEmbeddableWebComponents, featureFlags, diff --git a/flow-server/src/main/java/com/vaadin/flow/server/frontend/scanner/FullDependenciesScanner.java b/flow-server/src/main/java/com/vaadin/flow/server/frontend/scanner/FullDependenciesScanner.java index 9c4849fdd5f..addac63a97c 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/frontend/scanner/FullDependenciesScanner.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/frontend/scanner/FullDependenciesScanner.java @@ -91,7 +91,24 @@ class FullDependenciesScanner extends AbstractDependenciesScanner { * available feature flags and their status */ FullDependenciesScanner(ClassFinder finder, FeatureFlags featureFlags) { - this(finder, AnnotationReader::getAnnotationsFor, featureFlags); + this(finder, AnnotationReader::getAnnotationsFor, featureFlags, true); + } + + /** + * Creates a new scanner instance which discovers all dependencies in the + * classpath. + * + * @param finder + * a class finder + * @param featureFlags + * available feature flags and their status + * @param reactEnabled + * true if react classes are enabled + */ + FullDependenciesScanner(ClassFinder finder, FeatureFlags featureFlags, + boolean reactEnabled) { + this(finder, AnnotationReader::getAnnotationsFor, featureFlags, + reactEnabled); } /** @@ -104,10 +121,12 @@ class FullDependenciesScanner extends AbstractDependenciesScanner { * a strategy to discover class annotations * @param featureFlags * available feature flags and their status + * @param reactEnabled + * true if react classes are enabled */ FullDependenciesScanner(ClassFinder finder, SerializableBiFunction, Class, List> annotationFinder, - FeatureFlags featureFlags) { + FeatureFlags featureFlags, boolean reactEnabled) { super(finder, featureFlags); long start = System.currentTimeMillis(); @@ -144,6 +163,12 @@ class FullDependenciesScanner extends AbstractDependenciesScanner { collectScripts(scriptsSet, scriptsSetDevelopment, JavaScript.class); cssData = discoverCss(); + if (!reactEnabled) { + modulesSet.stream().filter( + module -> module.contains("ReactRouterOutletElement.tsx")) + .findFirst().ifPresent(outlet -> modulesSet.remove(outlet)); + } + modules = new ArrayList<>(modulesSet); modulesDevelopment = new ArrayList<>(modulesSetDevelopment); scripts = new ArrayList<>(scriptsSet); diff --git a/flow-server/src/test/java/com/vaadin/flow/server/frontend/scanner/FullDependenciesScannerTest.java b/flow-server/src/test/java/com/vaadin/flow/server/frontend/scanner/FullDependenciesScannerTest.java index ec6654dfe85..66887ce5339 100644 --- a/flow-server/src/test/java/com/vaadin/flow/server/frontend/scanner/FullDependenciesScannerTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/server/frontend/scanner/FullDependenciesScannerTest.java @@ -336,7 +336,7 @@ public void getModules_explcitTheme_returnAllModulesExcludingNotUsedTheme_getCla } Assert.fail(); return null; - }, null); + }, null, true); DepsTests.assertImportCount(28, scanner.getModules()); List modules = DepsTests.merge(scanner.getModules()); @@ -405,7 +405,7 @@ private FullDependenciesScanner setUpAnnotationScanner( return new FullDependenciesScanner(finder, (type, annotation) -> findAnnotations(type, annotationType), - null); + null, true); } private FullDependenciesScanner setUpThemeScanner( @@ -425,7 +425,8 @@ private FullDependenciesScanner setUpThemeScanner( Mockito.when(finder.getAnnotatedClasses(fakeNoThemeClass)) .thenReturn(noThemeClasses); - return new FullDependenciesScanner(finder, annotationFinder, null) { + return new FullDependenciesScanner(finder, annotationFinder, null, + true) { @Override protected Class getLumoTheme() { return FakeLumoTheme.class; diff --git a/flow-server/src/test/java/com/vaadin/flow/server/frontend/scanner/FullScannerPwaTest.java b/flow-server/src/test/java/com/vaadin/flow/server/frontend/scanner/FullScannerPwaTest.java index 93b59d9b5f8..20a8c05c552 100644 --- a/flow-server/src/test/java/com/vaadin/flow/server/frontend/scanner/FullScannerPwaTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/server/frontend/scanner/FullScannerPwaTest.java @@ -27,7 +27,8 @@ protected PwaConfiguration getPwaConfiguration(Class... classes) .getAnnotatedClasses(clazz); FullDependenciesScanner fullDependenciesScanner = new FullDependenciesScanner( - finder, (type, annotation) -> findPwaAnnotations(type), null); + finder, (type, annotation) -> findPwaAnnotations(type), null, + true); return fullDependenciesScanner.getPwaConfiguration(); }