Repository navigation
fix: Theme classes that are not set as theme do not add css - #22052
Conversation
Fix test expectations
9920ee6 to
e88fe25
Compare
Co-authored-by: Tomi Virtanen <tltv@vaadin.com>
|
tltv
left a comment
There was a problem hiding this comment.
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
| "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'\\}\\);"); |
There was a problem hiding this comment.
No way to understand what's going on here anymore.. it wasn't much better before either so refactoring may happen some other time.
There was a problem hiding this comment.
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.
| "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'\\}\\);"); |
|
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. |
|
This ticket/PR has been released with Vaadin 25.0.0-alpha7. |
* 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>



If
themeClassdefines CssImportthe import is not
taken into account if
the themeClass is not active.
Fixes #21605
Fixes #22014