Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: reintroduce locker flag to core #5246

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 10 additions & 8 deletions packages/@lwc/engine-core/src/framework/invoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { addErrorComponentStack } from '../shared/error';
import { evaluateTemplate, setVMBeingRendered, getVMBeingRendered } from './template';
import { runWithBoundaryProtection } from './vm';
import { logOperationStart, logOperationEnd, OperationId } from './profiler';
import type { LightningElement } from './base-lightning-element';
import { LightningElement } from './base-lightning-element';
import type { Template } from './template';
import type { VM } from './vm';
import type { LightningElementConstructor } from './base-lightning-element';
Expand Down Expand Up @@ -57,13 +57,15 @@ export function invokeComponentConstructor(vm: VM, Ctor: LightningElementConstru
// Check indirectly if the constructor result is an instance of LightningElement. Using
// the "instanceof" operator would not work here 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.

// TODO [W-17769475]: Restore this fix when we can reliably detect Locker enabled
// const isInvalidConstructor = lwcRuntimeFlags.LEGACY_LOCKER_ENABLED
// ? vmBeingConstructed.component !== result
// : !(result instanceof LightningElement);
const isInvalidConstructor = vmBeingConstructed.component !== result;
// invoked by accessing the component on the vm. In some core tests Legacy Locker is running
// on top of LWS so the flag will return false. The additional check for 'SecureLightningElement'
// is required for these cases.
const isLegacyLockerEnabled =
lwcRuntimeFlags.LEGACY_LOCKER_ENABLED ||
result?.toString()?.startsWith('SecureLightningElement');
const isInvalidConstructor = isLegacyLockerEnabled
? vmBeingConstructed.component !== result
: !(result instanceof LightningElement);

if (isInvalidConstructor) {
throw new TypeError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ it("[W-6981076] shouldn't throw when a component with an invalid child in unmoun
expect(() => document.body.removeChild(elm)).not.toThrow();
});

// TODO [W-17769475]: Restore this test when we can reliably detect Locker enabled
xit('should fail when the constructor returns something other than an instance of itself', () => {
it('should fail when the constructor returns something other than an instance of itself', () => {
expect(() => {
createElement('x-returning-bad', { is: ReturningBad });
}).toThrowError(
Expand Down