Flagsmith / flagsmith-js-client

Javascript Client for Flagsmith. Ship features with confidence using feature flags and remote config. Host yourself or use our hosted version at https://www.flagsmith.com/
https://www.flagsmith.com/
BSD 3-Clause "New" or "Revised" License
59 stars 36 forks source link

When `cacheFlags` is enabled, the cached `traits` value is not updated even when new values are passed to `init` #242

Closed pedroalves0 closed 6 days ago

pedroalves0 commented 1 month ago

It looks like it's the same problem reported in https://github.com/Flagsmith/flagsmith-js-client/issues/157, but for traits key instead of identity.

Our use case is the following:

  1. The flagsmith agent is first initialized with a certain user language as trait. Let's called it lang.
  2. The user changes the app language, which triggers a reload.
  3. When the Flagsmith agent is re-initalized, this time with lang set to the new language, Flagsmith overlooks the updated value and keeps using the cached data stored in the BULLET_TRAIN_DB.

From what I can see, the solution should be to extend this condition so that it also applies to traits.

novakzaballa commented 1 month ago

Hi @pedroalves0, we’ll take a look and get back to you as soon as possible.

henningmu commented 2 weeks ago

Hi @novakzaballa do you have an update for us on this? Should we be using the SDK differently?

novakzaballa commented 2 weeks ago

I'm sorry for the delay in responding. We confirmed this is an issue and will try to resolve it as soon as possible.

novakzaballa commented 1 week ago

I am handing off this issue to @kyle-ssg

kyle-ssg commented 1 week ago

Understanding the issue I think it's a bit debatable what should happen in this scenario, however, I think it the best behaviour would be to keep cached traits and overwrite with anything we find from flagsmith.init.

I've created a PR here. Additionally, this can be viewed in 4.0.4-beta.1 if you'd like to confirm everything is as expected.

Please let me know if this resolves your issue!

pedroalves0 commented 1 week ago

I confirm that the problem is fixed in 4.0.4-beta.1. Thanks for your help @kyle-ssg ! I'll keep an eye on when the fix gets deployed to main.

kyle-ssg commented 6 days ago

Published under 4.1.1! Thank you very much for testing / responding to the issue