---
schema_version: "1"
id: 7b17807a292be06bcd516d4ab6fa52e90a47371e7cf448f3461d47eb2475b316
title: Local Storage Limitations
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/lwc/lightning-components-security/guides/lws/lws-local-storage.md
canonical_url: https://developer.salesforce.com/docs/platform/lightning-components-security/guide/lws-local-storage.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 978757b4de34f9b149399d5aee6eeb27770fcfd9f0ce3fc7e1d332c994b12592
products:
  - Security for Lightning Components
  - lwc
---
# Local Storage Limitations

Lightning Web Security (LWS) creates synthetic storage for each sandbox. The synthetic storage prevents code in one sandbox from retrieving data that belongs to another namespace or that was set in the global scope outside LWS sandboxes.

`localStorage` and `sessionStorage` are partitioned by keys. When LWS is enabled, key values that are set outside the namespace aren’t accessible because LWS creates key names that are unique to the namespace.

To share data stored in local storage with code running in a different namespace, create a function and export it from one namespace to allow the other namespace to import and call the function.

**important:** Lightning Locker and LWS use different mechanisms for protecting local storage. Data that’s saved to local storage while Locker is enabled isn’t accessible when LWS is enabled, and vice versa. If the LWS setting changes after data is saved in local storage, the data isn’t accessible even when set by components in the same namespace. Rewrite the `localStorage` and `sessionStorage` data after enabling or disabling LWS.

**See Also**

[Storage API in Distortion Viewer](https://developer.salesforce.com/docs/component-library/tools/lws-distortion-viewer#Storage_constructor-value)
