-
Notifications
You must be signed in to change notification settings - Fork 31
feat: add legacy storage key cleanup functionality #1043
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
Conversation
- This saves a few bytes
- Introduced `getLegacyStorageKeys` method to as an optional internal option that could be configured per SDK. - Updated `LDClientImpl` to support cleaning old persistent data based on the new option `cleanOldPersistentData`. - Implemented `getLegacyStorageKeys` in Browser SDK so the feature is fully available there.
- Added a test to verify that old persistent data is cleaned while retaining current keys.
- Added a comment in `LDClientImpl.ts` to clarify that "override" changes are not being tracked as they are currently used only for debugging and not persisted. This may change in the future.
|
@launchdarkly/browser size report |
|
@launchdarkly/js-sdk-common size report |
|
@launchdarkly/js-client-sdk-common size report |
|
@launchdarkly/js-client-sdk size report |
| if (!isLocalStorageSupported()) { | ||
| return []; | ||
| } | ||
| return Object.keys(localStorage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not very comfortable with this approach to using local storage. While it can work it can have pitfalls if someone has, for example, done some monkey patching and only uses the local storage API instead of using it as POD.
I think we should use .length and .key()
const keys = [];
for (let i = 0; i < localStorage.length; i++) {
keys.push(localStorage.key(i);
}
return keys;🤖 I have created a release *beep* *boop* --- <details><summary>browser-telemetry: 1.0.16</summary> ## [1.0.16](browser-telemetry-v1.0.15...browser-telemetry-v1.0.16) (2026-01-06) ### Dependencies * The following workspace dependencies were updated * devDependencies * @launchdarkly/js-client-sdk bumped from 0.11.0 to 0.12.0 </details> <details><summary>jest: 0.2.0</summary> ## [0.2.0](jest-v0.1.15...jest-v0.2.0) (2026-01-06) ### Features * add waitForInitialization to RN SDK ([#1048](#1048)) ([13ce456](13ce456)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/react-native-client-sdk bumped from ~10.12.3 to ~10.12.4 </details> <details><summary>js-client-sdk: 0.12.0</summary> ## [0.12.0](js-client-sdk-v0.11.0...js-client-sdk-v0.12.0) (2026-01-06) ### Features * add legacy storage key cleanup functionality ([#1043](#1043)) ([fe4725e](fe4725e)) * add waitForInitialization to RN SDK ([#1048](#1048)) ([13ce456](13ce456)) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-client-sdk-common bumped from 1.16.0 to 1.17.0 </details> <details><summary>js-client-sdk-common: 1.17.0</summary> ## [1.17.0](js-client-sdk-common-v1.16.0...js-client-sdk-common-v1.17.0) (2026-01-06) ### Features * add legacy storage key cleanup functionality ([#1043](#1043)) ([fe4725e](fe4725e)) * add waitForInitialization to RN SDK ([#1048](#1048)) ([13ce456](13ce456)) </details> <details><summary>react-native-client-sdk: 10.12.4</summary> ## [10.12.4](react-native-client-sdk-v10.12.3...react-native-client-sdk-v10.12.4) (2026-01-06) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/js-client-sdk-common bumped from 1.16.0 to 1.17.0 </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Releases multiple packages and aligns versions/dependencies across the workspace. > > - Publish `@launchdarkly/js-client-sdk` 0.12.0 (adds legacy storage key cleanup); `@launchdarkly/js-client-sdk-common` 1.17.0; `@launchdarkly/react-native-client-sdk` 10.12.4; `@launchdarkly/browser-telemetry` 1.0.16; `@launchdarkly/jest` 0.2.0 (notes RN waitForInitialization) > - Bump deps to `@launchdarkly/[email protected]` in browser/RN SDKs and devDep `@launchdarkly/[email protected]` in telemetry; update `@launchdarkly/react-native-client-sdk` dep in `@launchdarkly/jest` > - Update version metadata in code (`BrowserInfo.ts`, `PlatformInfo.ts`) and `.release-please-manifest.json` > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 2d4e276. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Requirements
Related issues
sdk-569
Describe the solution you've provided
- Introduced
getLegacyStorageKeysmethod to as an optional internal option that could be configured per SDK.- Updated
LDClientImplto support cleaning old persistent data based on the new optioncleanOldPersistentData.- Implemented
getLegacyStorageKeysin Browser SDK so the feature is fully available there.- Added a test to verify that old persistent data is cleaned while retaining current keys.
Additional context
Additionally I've added some refactors that would address the following:
- changing Flagstore + FlagUpdater classes to interface (starting SDK-1686) which saves us a few bytes
- Added a comment in
LDClientImpl.tsto clarify that "override" changes are not being tracked as they are currently used only for debugging and not persisted. This may change in the future. (left over comment from a previous PR)Note
Introduces optional removal of legacy persisted data and refactors flag management internals.
LDOptions.cleanOldPersistentData(validated invalidators.ts); when enabled,LDClientImplclears keys returned byinternalOptions.getLegacyStorageKeysvia platform storage with error-tolerant loggingBrowserClientprovidesgetLegacyStorageKeysusinggetAllStorageKeysfromplatform/LocalStorage(filtersld:${clientSideId}:*)getAllStorageKeys()toLocalStorage.tsDefaultFlagStoreandFlagUpdaterclasses to interface + factory (createDefaultFlagStore,createFlagUpdater); update usages inFlagManager,FlagPersistence, and testsWritten by Cursor Bugbot for commit 8289e33. This will update automatically on new commits. Configure here.