Lightning Locker

To improve the security of your LWR apps, enable Lightning Locker.

Locker is a security architecture for Lightning web components (LWCs). To learn how Locker enhances the security of your components and code, visit Lightning Aura Components Developer Guide: Lightning Locker.

Compatibility with LWR 

  • Locker is only supported for applications in AMD mode. It doesn’t work for ESM mode. For more information about LWR application modes, see Set the LWR Server Modes.
  • Locker is only supported on the client-side. You can’t enable Locker for server-side code.

Enable Locker 

To opt-in to Locker, add the locker config to your project’s lwr.config.json. You can determine which components run outside of Locker by listing them in the trustedComponents property.

lwr.config.json
1{
2    "lwc": {
3        "modules": [{ "dir": "$rootDir/src/modules" }]
4    },
5    "locker": {
6        "enabled": true,
7        "trustedComponents": ["lightning/*", "example/app", "example/trustedCmp"]
8    },
9    "routes": [
10        {
11            "id": "locker-base",
12            "path": "/",
13            "rootComponent": "example/app",
14            "layoutTemplate": "$layoutsDir/main.html"
15        }
16    ]
17}

Developer Preview Feature

Feature is available as a developer preview. Feature is not generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. All commands, parameters, and other features are subject to change or deprecation at any time, with or without notice. Do not implement functionality developed with these commands or tools.