diff --git a/packages/@lwc/engine-core/src/framework/invoker.ts b/packages/@lwc/engine-core/src/framework/invoker.ts index 2448730d6e..822ed36966 100644 --- a/packages/@lwc/engine-core/src/framework/invoker.ts +++ b/packages/@lwc/engine-core/src/framework/invoker.ts @@ -58,10 +58,10 @@ export function invokeComponentConstructor(vm: VM, Ctor: LightningElementConstru // When Locker is enabled, the "instanceof" operator would not work since Locker Service // provides its own implementation of LightningElement, so we indirectly check // if the base constructor is invoked by accessing the component on the vm. - // When the ENABLE_LOCKER_VALIDATION gate is true and LEGACY_LOCKER_ENABLED is false, + // When the DISABLE_LOCKER_VALIDATION gate is false or LEGACY_LOCKER_ENABLED is false, // then the instanceof LightningElement can be used. const useLegacyConstructorCheck = - lwcRuntimeFlags.ENABLE_LEGACY_VALIDATION || lwcRuntimeFlags.LEGACY_LOCKER_ENABLED; + !lwcRuntimeFlags.DISABLE_LEGACY_VALIDATION || lwcRuntimeFlags.LEGACY_LOCKER_ENABLED; const isInvalidConstructor = useLegacyConstructorCheck ? vmBeingConstructed.component !== result diff --git a/packages/@lwc/features/src/index.ts b/packages/@lwc/features/src/index.ts index 2b0eb44cfd..2c4608d7b0 100644 --- a/packages/@lwc/features/src/index.ts +++ b/packages/@lwc/features/src/index.ts @@ -22,7 +22,7 @@ const features: FeatureFlagMap = { DISABLE_SYNTHETIC_SHADOW: null, DISABLE_SCOPE_TOKEN_VALIDATION: null, LEGACY_LOCKER_ENABLED: null, - ENABLE_LEGACY_VALIDATION: null, + DISABLE_LEGACY_VALIDATION: null, }; if (!(globalThis as any).lwcRuntimeFlags) { diff --git a/packages/@lwc/features/src/types.ts b/packages/@lwc/features/src/types.ts index ded6ae10a8..ab7984b7a8 100644 --- a/packages/@lwc/features/src/types.ts +++ b/packages/@lwc/features/src/types.ts @@ -92,7 +92,7 @@ export interface FeatureFlagMap { * If true, behave as if legacy Locker is enabled. * If false or unset, then the value of the `LEGACY_LOCKER_ENABLED` flag is used. */ - ENABLE_LEGACY_VALIDATION: FeatureFlagValue; + DISABLE_LEGACY_VALIDATION: FeatureFlagValue; } export type FeatureFlagName = keyof FeatureFlagMap; diff --git a/packages/@lwc/integration-karma/test/component/LightningElement/index.spec.js b/packages/@lwc/integration-karma/test/component/LightningElement/index.spec.js index a587358d18..2fe385dc68 100644 --- a/packages/@lwc/integration-karma/test/component/LightningElement/index.spec.js +++ b/packages/@lwc/integration-karma/test/component/LightningElement/index.spec.js @@ -81,24 +81,24 @@ it("[W-6981076] shouldn't throw when a component with an invalid child in unmoun expect(() => document.body.removeChild(elm)).not.toThrow(); }); -it('should fail when the constructor returns something other than LightningElement when ENABLE_LEGACY_VALIDATION is falsy and LEGACY_LOCKER_ENABLED is falsy', () => { +it('should fail when the constructor returns something other than LightningElement when DISABLE_LEGACY_VALIDATION is true and LEGACY_LOCKER_ENABLED is falsy', () => { + setFeatureFlagForTest('DISABLE_LEGACY_VALIDATION', true); expect(() => { createElement('x-returning-bad', { is: ReturningBad }); }).toThrowError( TypeError, 'Invalid component constructor, the class should extend LightningElement.' ); + setFeatureFlagForTest('DISABLE_LEGACY_VALIDATION', false); }); -it('should succeed when the constructor returns something other than LightningElement when ENABLE_LEGACY_VALIDATION is true and LEGACY_LOCKER_ENABLED is falsy', () => { - setFeatureFlagForTest('ENABLE_LEGACY_VALIDATION', true); +it('should succeed when the constructor returns something other than LightningElement when DISABLE_LEGACY_VALIDATION is falsy and LEGACY_LOCKER_ENABLED is falsy', () => { expect(() => { createElement('x-returning-bad', { is: ReturningBad }); }).not.toThrow(); - setFeatureFlagForTest('ENABLE_LEGACY_VALIDATION', false); }); -it('should succeed when the constructor returns something other than LightningElement when ENABLE_LEGACY_VALIDATION is falsy and LEGACY_LOCKER_ENABLED is true', () => { +it('should succeed when the constructor returns something other than LightningElement when DISABLE_LEGACY_VALIDATION is falsy and LEGACY_LOCKER_ENABLED is true', () => { setFeatureFlagForTest('LEGACY_LOCKER_ENABLED', true); expect(() => { createElement('x-returning-bad', { is: ReturningBad }); @@ -106,12 +106,12 @@ it('should succeed when the constructor returns something other than LightningEl setFeatureFlagForTest('LEGACY_LOCKER_ENABLED', false); }); -it('should succeed when the constructor returns something other than LightningElement when ENABLE_LEGACY_VALIDATION is falsy and LEGACY_LOCKER_ENABLED is true', () => { - setFeatureFlagForTest('ENABLE_LEGACY_VALIDATION', true); +it('should succeed when the constructor returns something other than LightningElement when DISABLE_LEGACY_VALIDATION is true and LEGACY_LOCKER_ENABLED is true', () => { + setFeatureFlagForTest('DISABLE_LEGACY_VALIDATION', true); setFeatureFlagForTest('LEGACY_LOCKER_ENABLED', true); expect(() => { createElement('x-returning-bad', { is: ReturningBad }); }).not.toThrow(); - setFeatureFlagForTest('ENABLE_LEGACY_VALIDATION', false); + setFeatureFlagForTest('DISABLE_LEGACY_VALIDATION', false); setFeatureFlagForTest('LEGACY_LOCKER_ENABLED', false); });