Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/@lwc/engine-core/src/framework/invoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/features/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/features/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,37 @@ 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 });
}).not.toThrow();
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);
});