Skip to content

Commit 968d30c

Browse files
fix: ensure to add feature-flags import at the start of bundle (#22329) (#22340)
The feature flags import in dev mode with the hot reload disabled ends up after the custom elements definition. This is problematic for cases, like the `layoutComponentsImprovements`, where the feature flag value is checked at the definition time to decide whether some CSS styles should be added or not. This change moves the appending of the feature flags import to the end of the method, and adds it at the start of the file. Fixes #vaadin/web-component#9571 Co-authored-by: Diego Cardoso <diego@vaadin.com>
1 parent 8ff6b80 commit 968d30c

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskGenerateBootstrap.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public class TaskGenerateBootstrap extends AbstractTaskClientGenerator {
7474
@Override
7575
protected String getFileContent() {
7676
List<String> lines = new ArrayList<>();
77-
lines.add(String.format("import './%s';%n", FEATURE_FLAGS_FILE_NAME));
7877
lines.add(String.format("import '%s';%n", getIndexTsEntryPath()));
7978
if (options.isReactEnabled()) {
8079
lines.add("import './vaadin-react.js';");
@@ -87,6 +86,8 @@ protected String getFileContent() {
8786
for (TypeScriptBootstrapModifier modifier : modifiers) {
8887
modifier.modify(lines, options, frontDeps);
8988
}
89+
lines.add(0,
90+
String.format("import './%s';%n", FEATURE_FLAGS_FILE_NAME));
9091
return String.join(System.lineSeparator(), lines);
9192
}
9293

flow-server/src/test/java/com/vaadin/flow/server/frontend/TaskGenerateBootstrapTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Collections;
2323
import java.util.List;
2424
import java.util.Map;
25+
import java.util.Set;
2526

2627
import org.junit.Assert;
2728
import org.junit.Before;
@@ -49,6 +50,7 @@ public class TaskGenerateBootstrapTest {
4950
private static final String DEV_TOOLS_IMPORT = "import '"
5051
+ FrontendUtils.JAR_RESOURCES_IMPORT
5152
+ "vaadin-dev-tools/vaadin-dev-tools.js';";
53+
private static final String CUSTOM_MODIFIER_CONTENT = "// custom modifier";
5254

5355
@Rule
5456
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -59,10 +61,18 @@ public class TaskGenerateBootstrapTest {
5961

6062
private Options options;
6163

64+
public static class CustomModifier implements TypeScriptBootstrapModifier {
65+
@Override
66+
public void modify(List<String> lines, Options options,
67+
FrontendDependenciesScanner scanner) {
68+
lines.add(0, CUSTOM_MODIFIER_CONTENT);
69+
}
70+
}
71+
6272
@Before
6373
public void setUp() throws Exception {
6474
ClassFinder.DefaultClassFinder finder = new ClassFinder.DefaultClassFinder(
65-
Collections.singleton(this.getClass()));
75+
Set.of(this.getClass(), CustomModifier.class));
6676
frontDeps = new FrontendDependenciesScanner.FrontendDependenciesScannerFactory()
6777
.createScanner(false, finder, false, null, true);
6878

@@ -125,6 +135,18 @@ public void should_importFeatureFlagTS() throws ExecutionFailedException {
125135
String.format("import './%s';", FEATURE_FLAGS_FILE_NAME)));
126136
}
127137

138+
@Test
139+
public void should_importFeatureFlagTSBeforeModifiers()
140+
throws ExecutionFailedException {
141+
taskGenerateBootstrap.execute();
142+
String content = taskGenerateBootstrap.getFileContent();
143+
int featureFlagIndex = content.indexOf(
144+
String.format("import './%s';", FEATURE_FLAGS_FILE_NAME));
145+
int modifierIndex = content.indexOf(CUSTOM_MODIFIER_CONTENT);
146+
Assert.assertTrue("Feature flag import should be before any modifier",
147+
featureFlagIndex < modifierIndex);
148+
}
149+
128150
@Test
129151
public void should_load_AppTheme()
130152
throws MalformedURLException, ExecutionFailedException {

0 commit comments

Comments
 (0)