Skip to content

Commit 03245e9

Browse files
authored
refactor: allow LumoInjector to be disabled at specific roots (#10542)
1 parent 53ba326 commit 03245e9

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

packages/vaadin-themable-mixin/lumo-injection-mixin.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,16 @@ export const LumoInjectionMixin = (superClass) =>
6868
connectedCallback() {
6969
super.connectedCallback();
7070

71+
const root = findRoot(this);
72+
73+
// Do not initialize LumoInjector if it's disabled at the root.
74+
// For example, Copilot does this because it uses its own styles
75+
// on top of the base styles, and Lumo injection would interfere.
76+
if (root.__lumoInjectorDisabled) {
77+
return;
78+
}
79+
7180
if (this.isConnected) {
72-
const root = findRoot(this);
7381
root.__lumoInjector ||= new LumoInjector(root);
7482
this.__lumoInjector = root.__lumoInjector;
7583
this.__lumoInjector.componentConnected(this);

packages/vaadin-themable-mixin/test/lumo-injection-mixin.test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@vaadin/chai-plugins';
2-
import { fixtureSync, nextRender, oneEvent } from '@vaadin/testing-helpers';
2+
import { fixtureSync, nextFrame, nextRender, oneEvent } from '@vaadin/testing-helpers';
33
import { css, html, LitElement } from 'lit';
44
import { LumoInjectionMixin } from '../lumo-injection-mixin.js';
55
import { registerStyles, ThemableMixin } from '../vaadin-themable-mixin.js';
@@ -428,6 +428,29 @@ describe('Lumo injection', () => {
428428
assertBaseStyle();
429429
});
430430
});
431+
432+
describe('injection disabled', () => {
433+
beforeEach(async () => {
434+
host.__lumoInjectorDisabled = true;
435+
host.shadowRoot.appendChild(element);
436+
await nextRender();
437+
content = element.shadowRoot.querySelector('[part="content"]');
438+
});
439+
440+
it('should not inject styles', async () => {
441+
const style = document.createElement('style');
442+
style.textContent = TEST_FOO_STYLES;
443+
document.head.appendChild(style);
444+
445+
await nextFrame();
446+
assertBaseStyle();
447+
448+
style.remove();
449+
450+
await nextFrame();
451+
assertBaseStyle();
452+
});
453+
});
431454
});
432455

433456
describe('nested component', () => {

0 commit comments

Comments
 (0)