Skip to content

Commit bb7685d

Browse files
fix: Ignore ?inline suffix for imported stylesheets (#16039) (#16040)
Frontend resources checking ignores ?inline suffixes in the stylesheet path when comparing file names. (cherry picked from commit b9da117) Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
1 parent 4dbafe1 commit bb7685d

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ private static boolean frontendImportsFound(JsonObject statsJson,
296296
.filter(line -> line.startsWith("import"))
297297
.map(line -> line.substring(line.indexOf('\'') + 1,
298298
line.lastIndexOf('\'')))
299+
.map(importString -> importString.contains("?")
300+
? importString.substring(0,
301+
importString.lastIndexOf("?"))
302+
: importString)
299303
.collect(Collectors.toList());
300304
JsonArray statsBundle = statsJson.hasKey("bundleImports")
301305
? statsJson.getArray("bundleImports")

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,38 @@ public void frontendFileHashMissmatch_bundleRebuild() throws IOException {
981981
}
982982
}
983983

984+
@Test
985+
public void cssImportWithInline_statsAndImportsMatchAndNoBundleRebuild()
986+
throws IOException {
987+
createPackageJsonStub(BLANK_PACKAGE_JSON_WITH_HASH);
988+
989+
final FrontendDependenciesScanner depScanner = Mockito
990+
.mock(FrontendDependenciesScanner.class);
991+
Mockito.when(depScanner.getModules()).thenReturn(
992+
Collections.singletonList("Frontend/my-styles.css?inline"));
993+
994+
JsonObject stats = getBasicStats();
995+
stats.getArray(BUNDLE_IMPORTS).set(0, "Frontend/my-styles.css");
996+
997+
try (MockedStatic<FrontendUtils> utils = Mockito
998+
.mockStatic(FrontendUtils.class)) {
999+
utils.when(() -> FrontendUtils.getDevBundleFolder(Mockito.any()))
1000+
.thenReturn(temporaryFolder.getRoot());
1001+
utils.when(
1002+
() -> FrontendUtils.getJarResourceString("my-styles.css"))
1003+
.thenReturn("body{color:yellow}");
1004+
utils.when(() -> FrontendUtils
1005+
.findBundleStatsJson(temporaryFolder.getRoot()))
1006+
.thenReturn(stats.toJson());
1007+
1008+
boolean needsBuild = TaskRunDevBundleBuild
1009+
.needsBuildInternal(options, depScanner, finder);
1010+
Assert.assertFalse(
1011+
"CSS 'inline' suffix should be ignored for imports checking",
1012+
needsBuild);
1013+
}
1014+
}
1015+
9841016
@Test
9851017
public void reusedTheme_noReusedThemes_noBundleRebuild()
9861018
throws IOException {

0 commit comments

Comments
 (0)