clear flags when changing groups mid-session - #3270
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the JS client SDK where changing feature-flag session groups mid-session would continue returning feature flags cached for the previous group set, preventing correct refetching for the new groups.
Changes:
- Clear the in-memory feature flag cache whenever
setFeatureFlagUserGroupsForSession()is called so subsequent flag reads refetch against the updated groups. - Add/expand unit tests to verify cache invalidation behavior and refetching after group changes.
- Add a small DataService API (
clearFeatureFlags) to support explicit cache invalidation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| clientlibs/js/src/UpGradeClient/UpgradeClient.ts | Clears cached feature flags when session groups are updated; ensures getAllFeatureFlags() refetches after group changes. |
| clientlibs/js/src/UpGradeClient/UpgradeClient.spec.ts | Adds tests asserting cache clearing and that the next getAllFeatureFlags() call refetches after group changes. |
| clientlibs/js/src/DataService/DataService.ts | Introduces clearFeatureFlags() to explicitly invalidate the feature flag cache. |
| clientlibs/js/src/DataService/DataService.spec.ts | Adds coverage for clearFeatureFlags() clearing previously cached flags. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bcb37
left a comment
There was a problem hiding this comment.
- Are we not caching per user/groups? Shouldn't it be the default behavior to refetch flags when user info has changed?
- Do we need to make this change in the Java client lib too?
|
#3267 this will unblock some work clc is trying to do, the ts client lib has a method for changing the groups that get sent with feature-flags, where a different set of groups could potentially fetch different flags. it had a bug though in that it doesn't clear previously fetched flags, so it always returned the flags for the original set of groups used. this now just clears the previous flags so that we'll successfully refetch.