Skip to content

Commit

Permalink
fix: No react module for Vaadin Router
Browse files Browse the repository at this point in the history
Remove reactOutlet module
if we are not running react,
but are using Vaadin Router
inferred from index.ts

Fixes #19870
  • Loading branch information
caalador committed Sep 3, 2024
1 parent f60a520 commit 7a73698
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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<?>, Class<? extends Annotation>, List<? extends Annotation>> annotationFinder,
FeatureFlags featureFlags) {
FeatureFlags featureFlags, boolean reactEnabled) {
super(finder, featureFlags);

long start = System.currentTimeMillis();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public void getModules_explcitTheme_returnAllModulesExcludingNotUsedTheme_getCla
}
Assert.fail();
return null;
}, null);
}, null, true);

DepsTests.assertImportCount(28, scanner.getModules());
List<String> modules = DepsTests.merge(scanner.getModules());
Expand Down Expand Up @@ -405,7 +405,7 @@ private FullDependenciesScanner setUpAnnotationScanner(

return new FullDependenciesScanner(finder,
(type, annotation) -> findAnnotations(type, annotationType),
null);
null, true);
}

private FullDependenciesScanner setUpThemeScanner(
Expand All @@ -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<? extends AbstractTheme> getLumoTheme() {
return FakeLumoTheme.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 7a73698

Please sign in to comment.