Skip to content

Commit

Permalink
fix: fix external url reference (#11039) (#11061)
Browse files Browse the repository at this point in the history
Fix the handling of external url reference in files that go into node_modules.
flow-frontend is copied directly to node_modules making css-loader
try to resolve urls for files that shouldn't be resolved.

Fixes #11015

Co-authored-by: caalador <mikael.grankvist@vaadin.com>
  • Loading branch information
vaadin-bot and caalador committed May 24, 2021
1 parent 7c47355 commit 56d4bcf
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion flow-server/src/main/resources/webpack.generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ module.exports = {
options: {
url: (url, resourcePath) => {
// Only translate files from node_modules
const resolve = resourcePath.match(/(\\|\/)node_modules\1/);
const resolve = resourcePath.match(/(\\|\/)node_modules\1/)
&& fs.existsSync(path.resolve(path.dirname(resourcePath), url));
const themeResource = resourcePath.match(themePartRegex) && url.match(/^themes\/[\s\S]*?\//);
return resolve || themeResource;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.vaadin.reusabletheme;

import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.dependency.NpmPackage;

@NpmPackage(value = "@fortawesome/fontawesome-free", version = "5.15.1")
@CssImport(value = "./css/styles.css")
public class Dependency {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.css-icon {
/* note that tests use path context fo which reason the image is placed in path/img */
background-image: url('img/icon.png');
background-size: 26px 26px;
}

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Import your application global css files here or add the styles directly to this file */
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.vaadin.flow.uitest.ui.theme;

import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Image;
Expand All @@ -26,6 +27,7 @@
@Route("com.vaadin.flow.uitest.ui.theme.ReusableThemeView")
@Theme(themeFolder = "reusable-theme")
@NpmPackage(value = "@vaadin/vaadin-themable-mixin", version = "1.6.1")
@CssImport(value = "./css/styles.css")
public class ReusableThemeView extends Div {

public static final String MY_POLYMER_ID = "field";
Expand Down Expand Up @@ -72,5 +74,9 @@ public ReusableThemeView() {
badge.getElement().setAttribute("theme", "badge");

add(badge);
Span cssIcon = new Span();
cssIcon.setId("css-icon");
cssIcon.setClassName("css-icon");
add(cssIcon);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ public void lumoBadgeIsRenderedCorrectly() {
Assert.assertEquals("rgba(22, 118, 243, 0.1)", badgeBackgroundColor);
}

@Test //11015
public void importedCssStyle_isUsed() {
open();
checkLogsForErrors();

final SpanElement cssIcon = $(SpanElement.class).id("css-icon");

Assert.assertEquals("url(\"" + getRootURL() + "/path/img/icon.png\")",
cssIcon.getCssValue("background-image"));
}

@Override
protected String getTestPath() {
String path = super.getTestPath();
Expand Down

0 comments on commit 56d4bcf

Please sign in to comment.