Skip to content

fix(electron-sdk): localstorage indexing#1262

Merged
joker23 merged 4 commits into
mainfrom
skz/sdk-2156/electron-localstorage
Apr 13, 2026
Merged

fix(electron-sdk): localstorage indexing#1262
joker23 merged 4 commits into
mainfrom
skz/sdk-2156/electron-localstorage

Conversation

@joker23

@joker23 joker23 commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

This PR will fix the localstorage indexing by removing the previous nested structure:

ldcache-{credential}

To:

ldcache

The new structure is more consistent with other SDKs by calculating the storage index purely out of the context canonical keys.

This PR will also serialize the write to this cache so that multiple instances of this SDK could exist.


Note

Medium Risk
Changes how all Electron SDK instances persist flag data by moving to a shared ldcache file and introducing singleton/queued flush behavior; this can affect cache isolation and persistence correctness across clients. Risk is mitigated by added tests, but storage/indexing regressions would impact offline/bootstrapped evaluations.

Overview
Switches Electron SDK persistent flag/context caching from per-credential files (e.g. ldcache-{credentialHash}) to a single shared ldcache file via a singleton ElectronStorage, aligning cache indexing purely with context-derived keys.

ElectronStorage now updates its in-memory cache first and serializes disk flushes through a queued atomic-write mechanism; initialization failures now surface as thrown errors (with cause) to the platform wrapper, which logs and swallows storage failures.

Updates contract tests to reset the storage singleton between clients and removes the singleton capability flag, and adds coverage for maxCachedContexts eviction/disabled caching plus new ElectronPlatform error-logging tests.

Reviewed by Cursor Bugbot for commit 81826d7. Bugbot is set up for automated code reviews on this repo. Configure here.


Open with Devin

@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 25661 bytes
Compressed size limit: 29000
Uncompressed size: 126143 bytes

@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 179348 bytes
Compressed size limit: 200000
Uncompressed size: 830127 bytes

@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 31736 bytes
Compressed size limit: 34000
Uncompressed size: 112937 bytes

@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 37181 bytes
Compressed size limit: 38000
Uncompressed size: 204409 bytes

@joker23

joker23 commented Apr 10, 2026

Copy link
Copy Markdown
Contributor Author

@cursor review

cursor[bot]

This comment was marked as resolved.

@joker23 joker23 force-pushed the skz/sdk-2156/electron-localstorage branch 2 times, most recently from 1ba2c69 to b327868 Compare April 10, 2026 16:48
@joker23

joker23 commented Apr 10, 2026

Copy link
Copy Markdown
Contributor Author

@cursor review

cursor[bot]

This comment was marked as resolved.

@joker23

joker23 commented Apr 10, 2026

Copy link
Copy Markdown
Contributor Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

1 issue from previous review remains unresolved.

Fix All in Cursor

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit f084d37. Configure here.

@joker23 joker23 marked this pull request as ready for review April 10, 2026 19:33
@joker23 joker23 requested a review from a team as a code owner April 10, 2026 19:33

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review


// Storage should be a singleton to support multiple instances of the SDK. This should have
// the same limitations as the browser sdk using the shared localStorage cache.
let instance: ElectronStorage | undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match JS we would likely need two layers here. This singleton holds a logger which means it will use the first logger encountered.

Where the JS storage is like an inner layer, and the outer layer isn't sharing. This implementation use a file, which is the equivalent of the singleton layer. Not to say we shouldn't use a singleton here, because the platform constraints are a little different, and this handles the cache consistency for us.

But we will likely want a nested approach.

Image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay I think this is addressed with the latest changes

@joker23 joker23 force-pushed the skz/sdk-2156/electron-localstorage branch from 38dc315 to b342d55 Compare April 13, 2026 19:24
cursor[bot]

This comment was marked as resolved.

@joker23 joker23 force-pushed the skz/sdk-2156/electron-localstorage branch from b342d55 to 81826d7 Compare April 13, 2026 19:35
@joker23 joker23 requested a review from kinyoklion April 13, 2026 19:36
@joker23 joker23 merged commit 42643d9 into main Apr 13, 2026
44 checks passed
@joker23 joker23 deleted the skz/sdk-2156/electron-localstorage branch April 13, 2026 20:30
@github-actions github-actions Bot mentioned this pull request Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants