Skip to content

Commit a36b0e8

Browse files
authored
fix: Add react classes in optimized mode (#19826)
* fix: Add react classes in optimized mode Add the react classes as found for optimized bundle. * get resource from finder instead of getting classloader
1 parent bad20b6 commit a36b0e8

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public FrontendDependencies(ClassFinder finder,
162162
visitEntryPoint(entryPoints.get(themeClass.getName()));
163163
}
164164
}
165+
computeReactClasses(finder);
165166
computePackages();
166167
computePwaConfiguration();
167168
aggregateEntryPointInformation();
@@ -175,6 +176,33 @@ public FrontendDependencies(ClassFinder finder,
175176
}
176177
}
177178

179+
private void computeReactClasses(ClassFinder finder) throws IOException {
180+
// Add ReactRouterOutlet and adapter as internal so it gets added to the
181+
// bundle if available.
182+
try {
183+
if (finder.getResource(
184+
"com/vaadin/flow/server/frontend/ReactRouterOutletElement.template") != null
185+
&& !visitedClasses.containsKey(
186+
"com.vaadin.flow.component.react.ReactRouterOutlet")) {
187+
Class<Object> entryPointClass = finder.loadClass(
188+
"com.vaadin.flow.component.react.ReactRouterOutlet");
189+
addInternalEntryPoint(entryPointClass);
190+
visitEntryPoint(entryPoints.get(entryPointClass.getName()));
191+
}
192+
if (finder.getResource(
193+
"com/vaadin/flow/server/frontend/ReactAdapter.template") != null
194+
&& !visitedClasses.containsKey(
195+
"com.vaadin.flow.component.react.ReactAdapterComponent")) {
196+
Class<Object> entryPointClass = finder.loadClass(
197+
"com.vaadin.flow.component.react.ReactAdapterComponent");
198+
addInternalEntryPoint(entryPointClass);
199+
visitEntryPoint(entryPoints.get(entryPointClass.getName()));
200+
}
201+
} catch (ClassNotFoundException cnfe) {
202+
// NO-OP
203+
}
204+
}
205+
178206
private void aggregateEntryPointInformation() {
179207
for (Entry<String, EntryPointData> entry : entryPoints.entrySet()) {
180208
EntryPointData entryPoint = entry.getValue();

0 commit comments

Comments
 (0)