Skip to content

Commit 8c03e50

Browse files
fix: invert locker contructor gate (#5337)
1 parent 529d080 commit 8c03e50

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

packages/@lwc/engine-core/src/framework/invoker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ export function invokeComponentConstructor(vm: VM, Ctor: LightningElementConstru
5858
// When Locker is enabled, the "instanceof" operator would not work since Locker Service
5959
// provides its own implementation of LightningElement, so we indirectly check
6060
// if the base constructor is invoked by accessing the component on the vm.
61-
// When the ENABLE_LOCKER_VALIDATION gate is true and LEGACY_LOCKER_ENABLED is false,
61+
// When the DISABLE_LOCKER_VALIDATION gate is false or LEGACY_LOCKER_ENABLED is false,
6262
// then the instanceof LightningElement can be used.
6363
const useLegacyConstructorCheck =
64-
lwcRuntimeFlags.ENABLE_LEGACY_VALIDATION || lwcRuntimeFlags.LEGACY_LOCKER_ENABLED;
64+
!lwcRuntimeFlags.DISABLE_LEGACY_VALIDATION || lwcRuntimeFlags.LEGACY_LOCKER_ENABLED;
6565

6666
const isInvalidConstructor = useLegacyConstructorCheck
6767
? vmBeingConstructed.component !== result

packages/@lwc/features/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const features: FeatureFlagMap = {
2222
DISABLE_SYNTHETIC_SHADOW: null,
2323
DISABLE_SCOPE_TOKEN_VALIDATION: null,
2424
LEGACY_LOCKER_ENABLED: null,
25-
ENABLE_LEGACY_VALIDATION: null,
25+
DISABLE_LEGACY_VALIDATION: null,
2626
};
2727

2828
if (!(globalThis as any).lwcRuntimeFlags) {

packages/@lwc/features/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export interface FeatureFlagMap {
9292
* If true, behave as if legacy Locker is enabled.
9393
* If false or unset, then the value of the `LEGACY_LOCKER_ENABLED` flag is used.
9494
*/
95-
ENABLE_LEGACY_VALIDATION: FeatureFlagValue;
95+
DISABLE_LEGACY_VALIDATION: FeatureFlagValue;
9696
}
9797

9898
export type FeatureFlagName = keyof FeatureFlagMap;

packages/@lwc/integration-karma/test/component/LightningElement/index.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,37 +81,37 @@ it("[W-6981076] shouldn't throw when a component with an invalid child in unmoun
8181
expect(() => document.body.removeChild(elm)).not.toThrow();
8282
});
8383

84-
it('should fail when the constructor returns something other than LightningElement when ENABLE_LEGACY_VALIDATION is falsy and LEGACY_LOCKER_ENABLED is falsy', () => {
84+
it('should fail when the constructor returns something other than LightningElement when DISABLE_LEGACY_VALIDATION is true and LEGACY_LOCKER_ENABLED is falsy', () => {
85+
setFeatureFlagForTest('DISABLE_LEGACY_VALIDATION', true);
8586
expect(() => {
8687
createElement('x-returning-bad', { is: ReturningBad });
8788
}).toThrowError(
8889
TypeError,
8990
'Invalid component constructor, the class should extend LightningElement.'
9091
);
92+
setFeatureFlagForTest('DISABLE_LEGACY_VALIDATION', false);
9193
});
9294

93-
it('should succeed when the constructor returns something other than LightningElement when ENABLE_LEGACY_VALIDATION is true and LEGACY_LOCKER_ENABLED is falsy', () => {
94-
setFeatureFlagForTest('ENABLE_LEGACY_VALIDATION', true);
95+
it('should succeed when the constructor returns something other than LightningElement when DISABLE_LEGACY_VALIDATION is falsy and LEGACY_LOCKER_ENABLED is falsy', () => {
9596
expect(() => {
9697
createElement('x-returning-bad', { is: ReturningBad });
9798
}).not.toThrow();
98-
setFeatureFlagForTest('ENABLE_LEGACY_VALIDATION', false);
9999
});
100100

101-
it('should succeed when the constructor returns something other than LightningElement when ENABLE_LEGACY_VALIDATION is falsy and LEGACY_LOCKER_ENABLED is true', () => {
101+
it('should succeed when the constructor returns something other than LightningElement when DISABLE_LEGACY_VALIDATION is falsy and LEGACY_LOCKER_ENABLED is true', () => {
102102
setFeatureFlagForTest('LEGACY_LOCKER_ENABLED', true);
103103
expect(() => {
104104
createElement('x-returning-bad', { is: ReturningBad });
105105
}).not.toThrow();
106106
setFeatureFlagForTest('LEGACY_LOCKER_ENABLED', false);
107107
});
108108

109-
it('should succeed when the constructor returns something other than LightningElement when ENABLE_LEGACY_VALIDATION is falsy and LEGACY_LOCKER_ENABLED is true', () => {
110-
setFeatureFlagForTest('ENABLE_LEGACY_VALIDATION', true);
109+
it('should succeed when the constructor returns something other than LightningElement when DISABLE_LEGACY_VALIDATION is true and LEGACY_LOCKER_ENABLED is true', () => {
110+
setFeatureFlagForTest('DISABLE_LEGACY_VALIDATION', true);
111111
setFeatureFlagForTest('LEGACY_LOCKER_ENABLED', true);
112112
expect(() => {
113113
createElement('x-returning-bad', { is: ReturningBad });
114114
}).not.toThrow();
115-
setFeatureFlagForTest('ENABLE_LEGACY_VALIDATION', false);
115+
setFeatureFlagForTest('DISABLE_LEGACY_VALIDATION', false);
116116
setFeatureFlagForTest('LEGACY_LOCKER_ENABLED', false);
117117
});

0 commit comments

Comments
 (0)