-
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
base: main
Are you sure you want to change the base?
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;
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
Adds an option to clear legacy persistent storage keys (implemented for browser) and refactors FlagStore/FlagUpdater into factory-based interfaces with corresponding updates and tests.
Introduces optional cleanup of legacy persistent storage and refactors in-memory flag components.
LDOptions.cleanOldPersistentData;LDClientImplusesinternalOptions.getLegacyStorageKeys()to asynchronously clear old keys (logs errors). Browser SDK implementsgetLegacyStorageKeysvia newplatform/LocalStorage.getAllStorageKeysand filters byld:${clientSideId}:*.DefaultFlagStore/FlagUpdaterclasses withFlagStoreinterface +createDefaultFlagStore()andcreateFlagUpdater()factories; updatesFlagManager,FlagPersistence, and tests accordingly.cleanOldPersistentDataand documents behavior; notes that "override" changes aren’t tracked for inspectors.Written by Cursor Bugbot for commit 6b67e86. This will update automatically on new commits. Configure here.