> output, boolean forWebcomponent) {
+ String prefix = ((forWebcomponent) ? "wc-" : "") + "chunk-";
return output.keySet().stream()
- .filter(file -> file.getName().contains("chunk-")).findAny();
+ .filter(file -> file.getName().startsWith(prefix)).findAny();
}
private void assertImports(String mainImportContent,
diff --git a/flow-tests/test-embedding/test-embedding-application-theme/src/main/frontend/css-import-component.css b/flow-tests/test-embedding/test-embedding-application-theme/src/main/frontend/css-import-component.css
new file mode 100644
index 00000000000..60394390016
--- /dev/null
+++ b/flow-tests/test-embedding/test-embedding-application-theme/src/main/frontend/css-import-component.css
@@ -0,0 +1,3 @@
+DIV.cssimport {
+ color: gold
+}
diff --git a/flow-tests/test-embedding/test-embedding-application-theme/src/main/java/com/vaadin/flow/webcomponent/CssImportComponent.java b/flow-tests/test-embedding/test-embedding-application-theme/src/main/java/com/vaadin/flow/webcomponent/CssImportComponent.java
new file mode 100644
index 00000000000..f8465170569
--- /dev/null
+++ b/flow-tests/test-embedding/test-embedding-application-theme/src/main/java/com/vaadin/flow/webcomponent/CssImportComponent.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2000-2024 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.flow.webcomponent;
+
+import com.vaadin.flow.component.Tag;
+import com.vaadin.flow.component.dependency.CssImport;
+import com.vaadin.flow.component.html.Div;
+
+@Tag("css-import-component")
+@CssImport("./css-import-component.css")
+public class CssImportComponent extends Div {
+
+ public CssImportComponent(String id) {
+ setId(id);
+ Div div = new Div(
+ "CssImport styles should be apply, this should not be black");
+ div.setClassName("cssimport");
+ add(div);
+ }
+}
diff --git a/flow-tests/test-embedding/test-embedding-application-theme/src/main/java/com/vaadin/flow/webcomponent/ThemedComponent.java b/flow-tests/test-embedding/test-embedding-application-theme/src/main/java/com/vaadin/flow/webcomponent/ThemedComponent.java
index 7752d6ea305..47794c5f2c6 100644
--- a/flow-tests/test-embedding/test-embedding-application-theme/src/main/java/com/vaadin/flow/webcomponent/ThemedComponent.java
+++ b/flow-tests/test-embedding/test-embedding-application-theme/src/main/java/com/vaadin/flow/webcomponent/ThemedComponent.java
@@ -18,7 +18,6 @@
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Span;
-
import com.vaadin.flow.uitest.ui.dependencies.TestVersion;
@NpmPackage(value = "@fortawesome/fontawesome-free", version = TestVersion.FONTAWESOME)
@@ -27,6 +26,7 @@ public class ThemedComponent extends Div {
public static final String TEST_TEXT_ID = "test-text";
public static final String MY_COMPONENT_ID = "field";
+ public static final String CSS_IMPORT_COMPONENT_ID = "embedded-cssimport";
public static final String EMBEDDED_ID = "embedded";
public static final String HAND_ID = "sparkle-hand";
@@ -45,5 +45,6 @@ public ThemedComponent() {
add(new Div());
add(new MyComponent().withId(MY_COMPONENT_ID));
+ add(new CssImportComponent(CSS_IMPORT_COMPONENT_ID));
}
}
diff --git a/flow-tests/test-embedding/test-embedding-application-theme/src/main/webapp/index.html b/flow-tests/test-embedding/test-embedding-application-theme/src/main/webapp/index.html
index a9dbc13515c..33e84c251fa 100644
--- a/flow-tests/test-embedding/test-embedding-application-theme/src/main/webapp/index.html
+++ b/flow-tests/test-embedding/test-embedding-application-theme/src/main/webapp/index.html
@@ -1,17 +1,20 @@
-
-
-
-
-
-
-
- Lumo styles should not be applied
- Internal should not apply, this should be black
- Document styles should apply, this should be blue
-
-
-
-
-
-
+
+
+
+
+
+ Lumo styles should not be applied
+
+ Internal should not apply, this should be black
+
+
+ CssImport styles should not apply, this should be black
+
+
+ Document styles should apply, this should be blue
+
+
+
+
+
diff --git a/flow-tests/test-embedding/test-embedding-application-theme/src/test/java/com/vaadin/flow/webcomponent/ApplicationThemeComponentIT.java b/flow-tests/test-embedding/test-embedding-application-theme/src/test/java/com/vaadin/flow/webcomponent/ApplicationThemeComponentIT.java
index 35a4de0793d..4ef5f8746e8 100644
--- a/flow-tests/test-embedding/test-embedding-application-theme/src/test/java/com/vaadin/flow/webcomponent/ApplicationThemeComponentIT.java
+++ b/flow-tests/test-embedding/test-embedding-application-theme/src/test/java/com/vaadin/flow/webcomponent/ApplicationThemeComponentIT.java
@@ -18,6 +18,7 @@
import java.util.List;
import java.util.stream.Collectors;
+import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.testbench.DivElement;
import com.vaadin.flow.component.html.testbench.H1Element;
import com.vaadin.flow.component.html.testbench.SpanElement;
@@ -103,6 +104,14 @@ private void validateEmbeddedComponent(TestBenchElement themedComponent,
Assert.assertEquals("Color should have been applied",
"rgba(0, 128, 0, 1)", handElement.getCssValue("color"));
+
+ // Ensure @CssImport styles are applied
+ final WebElement cssImportElement = embeddedComponent
+ .$("css-import-component").first().$(DivElement.class).single();
+ Assert.assertEquals(
+ "Color fom CSSImport annotation should have been applied",
+ "rgba(255, 215, 0, 1)", cssImportElement.getCssValue("color"));
+
}
@Test
@@ -246,4 +255,25 @@ public void lumoImports_doNotLeakEmbeddingPage() {
"rgba(0, 0, 0, 1)", element.getCssValue("color"));
}
+
+ @Test
+ public void cssImportAnnotation_doNotLeakEmbeddingPage() {
+ open();
+ checkLogsForErrors();
+
+ // Ensure embedded components are loaded before testing embedding page
+ validateEmbeddedComponent($("themed-component").id("first"), "first");
+ validateEmbeddedComponent($("themed-component").id("second"), "second");
+
+ final DivElement element = $(DivElement.class).withId("cssimport")
+ .waitForFirst();
+ Assert.assertFalse(
+ "Lumo styles (typography) should not have been applied to elements in embedding page",
+ element.getCssValue("font-family").contains("Roboto"));
+ Assert.assertEquals(
+ "Lumo styles (colors) should not have been applied to elements in embedding page",
+ "rgba(0, 0, 0, 1)", element.getCssValue("color"));
+
+ }
+
}