Skip to content

Commit

Permalink
chore: warn on shadowSupportMode 'any' (#3972)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekashida authored Feb 6, 2024
1 parent 4dceddb commit 1432a38
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/@lwc/engine-core/src/framework/def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
resolveCircularModuleDependency,
} from '../shared/circular-module-dependencies';

import { logError } from '../shared/logger';
import { logError, logWarn } from '../shared/logger';
import { instrumentDef } from './runtime-instrumentation';
import { EmptyObject } from './utils';
import { getComponentRegisteredTemplate } from './component';
Expand Down Expand Up @@ -122,6 +122,7 @@ function createComponentDef(Ctor: LightningElementConstructor): ComponentDef {

if (
!isUndefined(ctorShadowSupportMode) &&
ctorShadowSupportMode !== ShadowSupportMode.Any &&
ctorShadowSupportMode !== ShadowSupportMode.Default &&
ctorShadowSupportMode !== ShadowSupportMode.Native
) {
Expand All @@ -130,6 +131,13 @@ function createComponentDef(Ctor: LightningElementConstructor): ComponentDef {
);
}

// TODO [#3971]: Completely remove shadowSupportMode "any"
if (ctorShadowSupportMode === ShadowSupportMode.Any) {
logWarn(
`Invalid value 'any' for static property shadowSupportMode. 'any' is deprecated and will be removed in a future release--use 'native' instead.`
);
}

if (
!isUndefined(ctorRenderMode) &&
ctorRenderMode !== 'light' &&
Expand Down
1 change: 1 addition & 0 deletions packages/@lwc/engine-core/src/framework/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const enum ShadowMode {
}

export const enum ShadowSupportMode {
Any = 'any',
Default = 'reset',
Native = 'native',
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createElement } from 'lwc';
import { isNativeShadowRootInstance, isSyntheticShadowRootInstance } from 'test-utils';

import Any from 'x/any';
import Any2 from 'x/any2';
import Invalid from 'x/invalid';
import Valid from 'x/valid';
import NativeOnly from 'x/native';
Expand All @@ -15,7 +17,23 @@ describe('shadowSupportMode static property', () => {
it('should not throw for valid values', () => {
expect(() => {
createElement('x-valid', { is: Valid });
}).not.toThrowError();
}).not.toLogErrorDev();
});

// TODO [#3971]: Completely remove shadowSupportMode "any"
it('should warn for deprecated value "any"', () => {
// eslint-disable-next-line jest/valid-expect
expect(() => {
createElement('x-any', { is: Any });
}).toLogWarningDev(/Invalid value 'any' for static property shadowSupportMode/);

if (process.env.SYNTHETIC_SHADOW_ENABLED && !process.env.MIXED_SHADOW) {
let elm;
expect(() => {
elm = createElement('x-any2', { is: Any2 });
}).toLogWarningDev(/Invalid value 'any' for static property shadowSupportMode/);
expect(isSyntheticShadowRootInstance(elm.shadowRoot)).toBe(true);
}
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';
}

0 comments on commit 1432a38

Please sign in to comment.