Page MenuHomePhabricator

[native] Cache feature flags config
ClosedPublic

Authored by tomek on Jul 28 2023, 9:12 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Jul 3, 10:05 PM
Unknown Object (File)
Wed, Jul 3, 8:39 AM
Unknown Object (File)
Tue, Jul 2, 5:48 AM
Unknown Object (File)
Tue, Jul 2, 4:19 AM
Unknown Object (File)
Sun, Jun 30, 3:47 AM
Unknown Object (File)
Sat, Jun 22, 1:02 AM
Unknown Object (File)
Fri, Jun 21, 9:57 AM
Unknown Object (File)
Fri, Jun 21, 9:57 AM
Subscribers

Details

Summary

Save fetched feature flags config in AsyncStorage. When the app starts, read the value from the storage and override it with a value from service when it is fetched.

This diff is an implementation of point 2 from https://linear.app/comm/issue/ENG-3252/improve-feature-flags-reliability

Test Plan

Ran the app and checked if after fresh start no value is read from the store and config is set after successful fetch. Then checked if restarting the app causes AsyncStorage read and saving to state which is then replaced by the config from service.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

native/components/feature-flags-provider.react.js
54 ↗(On Diff #29180)

We're checking this condition twice (here and in the 42nd line) because it is possible that during AsyncStorage read the value was fetched and set from the service.

tomek requested review of this revision.Jul 28 2023, 9:30 AM
This revision is now accepted and ready to land.Jul 31 2023, 2:41 AM
native/components/feature-flags-provider.react.js
3 ↗(On Diff #29180)

I'm not sure we should use AsyncStorage for this. We want to add support for feature flags to the web eventually, and by using something specific to React Native here, we'll make it harder to do that

Do you think it's a bad idea to use Redux for this?

native/components/feature-flags-provider.react.js
3 ↗(On Diff #29180)

The reasoning behind this decision was that I wanted for feature flags to be available as high in a tree as possible. Especially, I thought that they might be useful even for things that affect what we do with Redux - so Redux should depend on flags, not the other way around. If we store them in Redux, we would get cached values only after rehydration, so a lot of things might be hard to be configured by them. Also, the flags provider would be located deeper in a tree (probably could be somehow worked around).

On the web, we can use e.g. localStorage. This difference can be abstracted away and most of the logic still could be shared. The logic that will be different will be really simple - just read and write.

So overall, it seems worth having this difference because it makes flags more powerful. But if you disagree, I can change the implementation.

Clear cached flags after wipeAndExit

native/components/feature-flags-provider.react.js
3 ↗(On Diff #29180)

Okay, fair enough – thanks for explaining

This revision was automatically updated to reflect the committed changes.