Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public boolean synchronizedHandleRequest(VaadinSession session,

configureHiddenElementStyles(indexDocument);

addStyleTagReferences(indexDocument);
addStyleTagReferences(indexDocument, config.isProductionMode());

response.setContentType(CONTENT_TYPE_TEXT_HTML_UTF_8);

Expand Down Expand Up @@ -203,12 +203,30 @@ private void applyThemeVariant(Document indexDocument,
.head().parent().attr("theme", theme.variant()));
}

private void addStyleTagReferences(Document indexDocument) {
Comment cssImportComment = new Comment("CSSImport end");
indexDocument.head().appendChild(cssImportComment);
private void addStyleTagReferences(Document indexDocument,
boolean productionMode) {
int insertLocation = -1; // At the end
if (productionMode) {
/*
* In production mode, the theme css is included by Vite in
* index.html. The CSS override order has been specified so that the
* theme should override all other CSS, so it must come last and we
* must insert before that.
*
* We don't really know which link tag it is, if there are multiple,
* so we use the first. Then all link tags override css imports.
*/
Elements links = indexDocument.head().getElementsByTag("link");
if (!links.isEmpty()) {
insertLocation = indexDocument.head().childNodes()
.indexOf(links.first());
}
}

Comment cssImportComment = new Comment("CSSImport end");
Comment stylesheetComment = new Comment("Stylesheet end");
indexDocument.head().appendChild(stylesheetComment);
indexDocument.head().insertChildren(insertLocation, cssImportComment,
stylesheetComment);
}

private void redirectToOldBrowserPageWhenNeeded(Document indexDocument) {
Expand Down
3 changes: 0 additions & 3 deletions flow-tests/test-themes/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
height: 100%;
}
</style>
<custom-style>
<style include="lumo-color lumo-typography"></style>
</custom-style>
<!-- index.ts is included here automatically (either by the dev server or during the build) -->
</head>

Expand Down