Skip to content

Commit 29259ea

Browse files
vaadin-botArtur-mshabarov
authored
fix: Do not import Lumo twice for the document (#16243) (#16257)
* fix: Do not import Lumo twice for the document All Lumo modules except utility are loaded and injected into <head> by https://github.com/vaadin/flow-components/blob/main/vaadin-lumo-theme-flow-parent/vaadin-lumo-theme-flow/src/main/java/com/vaadin/flow/theme/lumo/Lumo.java We should not do that another time * Update flow-server/src/main/resources/plugins/application-theme-plugin/theme-generator.js --------- Co-authored-by: Artur <artur@vaadin.com> Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
1 parent f9e8802 commit 29259ea

1 file changed

Lines changed: 20 additions & 31 deletions

File tree

‎flow-server/src/main/resources/plugins/application-theme-plugin/theme-generator.js‎

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,6 @@ export const injectGlobalCss = (css, target, first) => {
9999
};
100100
`;
101101

102-
const addLumoImportStyleTag = `
103-
const addLumoImportStyleTag = (lumoStyles, target) => {
104-
const styleTag = document.createElement('style');
105-
styleTag.type = 'text/css';
106-
styleTag.appendChild(document.createTextNode(lumoStyles));
107-
// For target document append to head else append to target
108-
if (target === document) {
109-
document.head.appendChild(styleTag);
110-
} else {
111-
target.appendChild(styleTag);
112-
}
113-
};
114-
`;
115-
116102
/**
117103
* Generate the [themeName].js file for themeFolder which collects all required information from the folder.
118104
*
@@ -149,11 +135,11 @@ function generateThemeFile(themeFolder, themeName, themeProperties, options) {
149135

150136
themeFile += createLinkReferences;
151137
themeFile += injectGlobalCssMethod;
152-
themeFile += addLumoImportStyleTag;
153138

154139
const imports = [];
155140
const globalCssCode = [];
156141
const lumoCssCode = [];
142+
const lumoCssShadowOnlyCode = [];
157143
const componentCssCode = [];
158144
const parentTheme = themeProperties.parent ? 'applyBaseTheme(target);\n' : '';
159145

@@ -186,15 +172,14 @@ function generateThemeFile(themeFolder, themeName, themeProperties, options) {
186172
imports.push(`import { ${lumoImport} } from '@vaadin/vaadin-lumo-styles/${lumoImport}.js';\n`);
187173
});
188174

189-
if (useDevServer) {
190-
lumoImports.forEach((lumoImport) => {
175+
lumoImports.forEach((lumoImport) => {
176+
// Lumo is injected to the document by Lumo itself, except for the utility module
177+
if (lumoImport === 'utility') {
191178
lumoCssCode.push(`injectGlobalCss(${lumoImport}.cssText, target, true);\n`);
192-
});
193-
} else {
194-
lumoImports.forEach((lumoImport) => {
195-
lumoCssCode.push(`addLumoImportStyleTag(${lumoImport}.cssText, target);\n`);
196-
});
197-
}
179+
} else {
180+
lumoCssShadowOnlyCode.push(`injectGlobalCss(${lumoImport}.cssText, target, true);\n`);
181+
}
182+
});
198183
}
199184

200185
if (useDevServer) {
@@ -308,15 +293,19 @@ function getHash(input) {
308293
// Don't format as the generated file formatting will get wonky!
309294
// If targets check that we only register the style parts once, checks exist for global css and component css
310295
const themeFileApply = `export const applyTheme = (target) => {
311-
${parentTheme}
312-
${globalCssCode.join('')}
313-
314-
if (!document['${componentCssFlag}']) {
315-
${componentCssCode.join('')}
316-
document['${componentCssFlag}'] = true;
296+
if (target !== document) {
297+
// Lumo is injected to the document by Lumo itself, except for the utility module
298+
${lumoCssShadowOnlyCode.join('')}
299+
}
300+
${lumoCssCode.join('')}
301+
${parentTheme}
302+
${globalCssCode.join('')}
303+
304+
if (!document['${componentCssFlag}']) {
305+
${componentCssCode.join('')}
306+
document['${componentCssFlag}'] = true;
307+
}
317308
}
318-
${lumoCssCode.join('')}
319-
}
320309
`;
321310

322311
themeFile += themeFileApply;

0 commit comments

Comments
 (0)