Skip to content

Commit faae5c3

Browse files
authored
fix: Support Theme annotation with only defaults (#22738)
Support having Theme annotation with only default values in production mode byte scanning. Previously we always fell back on Lumo so the not seen Theme annotation didn't have an impact. Fixes #22731
1 parent 881ab0c commit faae5c3

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

flow-server/src/main/java/com/vaadin/flow/server/frontend/scanner/FrontendClassVisitor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ public AnnotationVisitor visitAnnotation(String descriptor,
284284
return null;
285285
}
286286
if (annotationClassName.contains(Theme.class.getName())) {
287+
classInfo.theme.themeAnnotationPresent = true;
287288
return themeVisitor;
288289
}
289290
if (annotationClassName.contains(CssImport.class.getName())) {

flow-server/src/main/java/com/vaadin/flow/server/frontend/scanner/FrontendDependencies.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,9 @@ private boolean hasThemeInfo(ClassInfo classInfo) {
944944
if (theme.isNotheme()) {
945945
return true;
946946
}
947+
if (theme.themeAnnotationPresent) {
948+
return true;
949+
}
947950

948951
return false;
949952
}

flow-server/src/main/java/com/vaadin/flow/server/frontend/scanner/ThemeData.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ final class ThemeData implements Serializable {
3131
String variant = "";
3232
String themeName = "";
3333
boolean notheme;
34+
boolean themeAnnotationPresent;
3435

3536
ThemeData(String themeClass, String variant, String themeName) {
3637
this.themeClass = themeClass;
@@ -70,6 +71,7 @@ public boolean equals(Object other) {
7071
}
7172
ThemeData that = (ThemeData) other;
7273
return notheme == that.notheme
74+
&& themeAnnotationPresent == that.themeAnnotationPresent
7375
&& Objects.equals(themeClass, that.themeClass)
7476
&& Objects.equals(themeName, that.themeName);
7577
}
@@ -79,12 +81,14 @@ public int hashCode() {
7981
// We might need to add variant when we wanted to fail in the
8082
// case of same theme class with different variant, which was
8183
// right in v13
82-
return Objects.hash(themeClass, notheme, themeName);
84+
return Objects.hash(themeClass, notheme, themeName,
85+
themeAnnotationPresent);
8386
}
8487

8588
@Override
8689
public String toString() {
87-
return " notheme: " + notheme + "\n themeClass:" + themeClass
90+
return " notheme: " + notheme + "\n themeAnnotationPresent: "
91+
+ themeAnnotationPresent + "\n themeClass:" + themeClass
8892
+ "\n variant: " + variant + "\n themeName: " + themeName;
8993
}
9094
}

flow-server/src/test/java/com/vaadin/flow/server/frontend/scanner/FrontendDependenciesTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,30 @@ public void onlyThemeVariantDefined_getsLumoAsTheme_preserveVariant() {
211211
dependencies.getThemeDefinition().getVariant());
212212
}
213213

214+
@Test
215+
public void defaultThemeAnnotation_getsLumoAsTheme() {
216+
Mockito.when(classFinder.getSubTypesOf(AppShellConfigurator.class))
217+
.thenReturn(
218+
Collections.singleton(DefaultThemeAnnotation.class));
219+
220+
FrontendDependencies dependencies = new FrontendDependencies(
221+
classFinder, false, null, true);
222+
223+
AbstractTheme theme = dependencies.getTheme();
224+
Assert.assertNotNull(
225+
"Theme should be found for @Theme with default values", theme);
226+
227+
ThemeDefinition themeDefinition = dependencies.getThemeDefinition();
228+
Assert.assertNotNull("ThemeDefinition should be filled",
229+
themeDefinition);
230+
Assert.assertEquals("Should default to Lumo theme", FakeLumo.class,
231+
themeDefinition.getTheme());
232+
Assert.assertEquals("Variant should be empty", "",
233+
themeDefinition.getVariant());
234+
Assert.assertEquals("Theme name should be empty", "",
235+
themeDefinition.getName());
236+
}
237+
214238
@Test
215239
public void hasErrorParameterComponent_entryPointIsCollected() {
216240
Mockito.when(classFinder.getSubTypesOf(HasErrorParameter.class))
@@ -554,6 +578,10 @@ public static class FaultyThemeAnnotation implements AppShellConfigurator {
554578
public static class ThemeVariantOnly implements AppShellConfigurator {
555579
}
556580

581+
@Theme
582+
public static class DefaultThemeAnnotation implements AppShellConfigurator {
583+
}
584+
557585
@JsModule("reference.js")
558586
@Tag("div")
559587
public static class Referenced extends Component {

0 commit comments

Comments
 (0)