Skip to content

fix: Theme classes that are not set as theme do not add css - #22052

Merged
mshabarov merged 6 commits into
mainfrom
issues/21605-lumo-css
Aug 20, 2025
Merged

mshabarov merged 6 commits into
mainfrom
issues/21605-lumo-css

Conversation

@caalador

Copy link
Copy Markdown
Contributor

If themeClass defines CssImport
the import is not
taken into account if
the themeClass is not active.

Fixes #21605
Fixes #22014

If `themeClass` defines CssImport
the import is not
taken into account if
the themeClass is not active.

Fixes #21605
Fixes #22014
@github-actions

github-actions Bot commented Aug 18, 2025 •

Copy link
Copy Markdown
Contributor

Test Results

1 240 files  ± 0  1 240 suites  ±0   1h 14m 49s ⏱️ + 1m 31s
8 568 tests + 4  8 501 ✅ + 4  67 💤 ±0  0 ❌ ±0 
8 918 runs  +64  8 843 ✅ +62  75 💤 +2  0 ❌ ±0 

Results for commit 1b99661. ± Comparison against base commit eb4cb28.

♻️ This comment has been updated with latest results.

@caalador
caalador force-pushed the issues/21605-lumo-css branch from 9920ee6 to e88fe25 Compare August 18, 2025 09:59
@vaadin-bot vaadin-bot added +1.0.0 and removed +0.0.1 labels Aug 18, 2025
@mshabarov
mshabarov requested a review from tltv August 18, 2025 11:34
caalador and others added 2 commits August 19, 2025 06:52
Co-authored-by: Tomi Virtanen <tltv@vaadin.com>
@vaadin-bot vaadin-bot added +0.0.1 and removed +1.0.0 labels Aug 19, 2025
@sonarqubecloud

Copy link
Copy Markdown

@tltv tltv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested quick with walking skeleton app: works as expected in dev bundle, hotdeploy and production mode. Theme's CssImport is added only when theme is actually used with Theme annotation.

However, when I remove Theme annotation from a project and run production build, bundle is not rebuild. This may be different topic and can be handled separately.

[INFO] Checking if a production mode bundle build is needed
[INFO] A production mode bundle build is not needed

Comment on lines +119 to +150
"import \\$cssFromFile_\\d from '@vaadin/vaadin-mixed-component/bar.css\\?inline'");
expectedLines.add(
"import { css, unsafeCSS, registerStyles } from '@vaadin/vaadin-themable-mixin';");
"import \\$cssFromFile_\\d from 'Frontend/foo.css\\?inline';");
expectedLines.add(
"injectGlobalCss($cssFromFile_0.toString(), 'CSSImport end', document);");
"import \\$cssFromFile_\\d from 'Frontend/foo.css\\?inline';");
expectedLines.add(
"injectGlobalCss($cssFromFile_1.toString(), 'CSSImport end', document);");
expectedLines.add("function addCssBlock(block) {");
"import \\$cssFromFile_\\d from 'Frontend/foo.css\\?inline';");
expectedLines.add(
"addCssBlock(`<style include=\"bar\">${$css_2}</style>`);");
expectedLines.add("registerStyles('', $css_3, {moduleId: 'baz'});");
"import \\$cssFromFile_\\d from 'Frontend/foo.css\\?inline';");
expectedLines.add(
"registerStyles('', $css_4, {include: 'bar', moduleId: 'baz'});");
"import \\$cssFromFile_\\d from 'Frontend/foo.css\\?inline';");
expectedLines.add(
"registerStyles('foo-bar', $css_5, {moduleId: 'flow_css_mod_5'});");
"import \\$cssFromFile_\\d from 'Frontend/foo.css\\?inline';");
expectedLines.add(
"registerStyles('foo-bar', $css_6, {include: 'bar', moduleId: 'flow_css_mod_6'});");
"import \\$cssFromFile_\\d from 'Frontend/foo.css\\?inline';");
expectedLines.add(
"import \\{ css, unsafeCSS, registerStyles \\} from '@vaadin/vaadin-themable-mixin';");
expectedLines.add(
"injectGlobalCss\\(\\$cssFromFile_\\d.toString\\(\\), 'CSSImport end', document\\);");
expectedLines.add(
"injectGlobalCss\\(\\$cssFromFile_\\d.toString\\(\\), 'CSSImport end', document\\);");
expectedLines.add("function addCssBlock\\(block\\) \\{");
expectedLines.add(
"addCssBlock\\(`<style include=\"bar\">\\$\\{\\$css_\\d\\}</style>`\\);");
expectedLines.add(
"registerStyles\\('', \\$css_\\d, \\{moduleId: 'baz'\\}\\);");
expectedLines.add(
"registerStyles\\('', \\$css_\\d, \\{include: 'bar', moduleId: 'baz'\\}\\);");
expectedLines.add(
"registerStyles\\('foo-bar', \\$css_\\d, \\{moduleId: 'flow_css_mod_\\d'\\}\\);");
expectedLines.add(
"registerStyles\\('foo-bar', \\$css_\\d, \\{include: 'bar', moduleId: 'flow_css_mod_\\d'\\}\\);");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No way to understand what's going on here anymore.. it wasn't much better before either so refactoring may happen some other time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It checks the generated imports to see that expected lines are available, but the Theme that is added to the tests gets injected in the beginning for full scanner and end for byte scanner so we can not for both modes check that $cssFromFile_0 import is vaadin-mixed-component as depending on the scanner used for the test it might be the new lumo-css-import.css from the theme class.
So the only change is basically that we accept the number to be any number. So they are now regex checked lines.

Comment on lines +326 to +354
"import \\$cssFromFile_\\d from '@vaadin/vaadin-mixed-component/bar.css\\?inline';");
expectedLines.add(
"import \\$cssFromFile_\\d from 'Frontend/foo.css\\?inline';");
expectedLines.add(
"import \\$cssFromFile_\\d from 'Frontend/foo.css\\?inline';");
expectedLines.add(
"import \\$cssFromFile_\\d from 'Frontend/foo.css\\?inline';");
expectedLines.add(
"import \\$cssFromFile_\\d from 'Frontend/foo.css\\?inline';");
expectedLines.add(
"import \\$cssFromFile_\\d from 'Frontend/foo.css\\?inline';");
expectedLines.add(
"import \\$cssFromFile_\\d from 'Frontend/foo.css\\?inline';");
expectedLines.add(
"import \\$cssFromFile_\\d from 'lumo-css-import.css\\?inline';");
expectedLines.add(
"injectGlobalCss\\(\\$cssFromFile_\\d.toString\\(\\), 'CSSImport end', document\\);");
expectedLines.add(
"injectGlobalCss($cssFromFile_0.toString(), 'CSSImport end', document);");
"injectGlobalCss\\(\\$cssFromFile_\\d.toString\\(\\), 'CSSImport end', document\\);");
expectedLines.add(
"injectGlobalCss($cssFromFile_1.toString(), 'CSSImport end', document);");
"addCssBlock\\(`<style include=\"bar\">\\$\\{\\$css_\\d\\}</style>`\\);");
expectedLines.add(
"addCssBlock(`<style include=\"bar\">${$css_2}</style>`);");
expectedLines.add("registerStyles('', $css_3, {moduleId: 'baz'});");
"registerStyles\\('', \\$css_\\d, \\{moduleId: 'baz'\\}\\);");
expectedLines.add(
"registerStyles('', $css_4, {include: 'bar', moduleId: 'baz'});");
"registerStyles\\('', \\$css_\\d, \\{include: 'bar', moduleId: 'baz'\\}\\);");
expectedLines.add(
"registerStyles('foo-bar', $css_5, {moduleId: 'flow_css_mod_5'});");
"registerStyles\\('foo-bar', \\$css_\\d, \\{moduleId: 'flow_css_mod_\\d'\\}\\);");
expectedLines.add(
"registerStyles('foo-bar', $css_6, {include: 'bar', moduleId: 'flow_css_mod_6'});");
"registerStyles\\('foo-bar', \\$css_\\d, \\{include: 'bar', moduleId: 'flow_css_mod_\\d'\\}\\);");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here.

@caalador

Copy link
Copy Markdown
Contributor Author

The rebuild perhaps needs to be checked if it adds the theme, as we accept having too many things in the bundle, but rebuild for missing things.

@mshabarov
mshabarov merged commit 8651d8d into main Aug 20, 2025
@mshabarov
mshabarov deleted the issues/21605-lumo-css branch August 20, 2025 07:14
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 25.0.0-alpha7.

Copilot AI pushed a commit that referenced this pull request Oct 1, 2025
* fix: Theme classes that are not set as theme do not add css

If `themeClass` defines CssImport
the import is not
taken into account if
the themeClass is not active.

Fixes #21605
Fixes #22014

* Fix classes with theme to collect only differing themes

Fix test expectations

* ignore non found class definitions

* Fix test name typo

Co-authored-by: Tomi Virtanen <tltv@vaadin.com>

---------

Co-authored-by: Tomi Virtanen <tltv@vaadin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lumo theme is loaded in dev mode although no @Theme annotation is present (v25) Lumo class should be deprecated and just load stylesheets in V25

4 participants