Skip to content
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

chore: Synchronous web cache #222

Merged
merged 8 commits into from
Mar 28, 2024
Merged

chore: Synchronous web cache #222

merged 8 commits into from
Mar 28, 2024

Conversation

kyle-ssg
Copy link
Member

@kyle-ssg kyle-ssg commented Mar 26, 2024

Web supports synchronous cache, this PR adjusts the SDK in the following ways

  • If an AsyncStorage object is provided with getItemSync, it'll use this synchronously.
  • Removes @callstack/async-storage, unnecessary and date dependency.
  • Adds chore: add withTraits when setting state #221
  • Minor: removes empty test folder from lib folders.

The previous behaviour happened to cause undesired behaviour on OpenFeature's react implementation open-feature/js-sdk#881. Essentially, getting AsyncStorage in Flagsmith.init is so quick there's a race condition between useEffect(Where change listeners are setup for hooks). We saw similar behaviour before and opted to use refs for setting up listeners.

…nchronous-web-cache

# Conflicts:
#	lib/flagsmith-es/package.json
#	lib/flagsmith/package.json
#	lib/react-native-flagsmith/package.json
Copy link
Contributor

@novakzaballa novakzaballa left a comment

Choose a reason for hiding this comment

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

LGTM

async-storage.ts Outdated
Comment on lines 8 to 9
const data = localStorage.getItem(key);
return data || null
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we wrap this in a try catch?

@kyle-ssg kyle-ssg merged commit 68fe0e8 into main Mar 28, 2024
1 check passed
@kyle-ssg kyle-ssg deleted the chore/synchronous-web-cache branch March 28, 2024 19:03
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.

None yet

2 participants