launchdarkly / react-client-sdk

LaunchDarkly Client-side SDK for React.js
Other
86 stars 68 forks source link

Fix bug in asyncWithLDProvider #13

Closed tarqd closed 4 years ago

tarqd commented 4 years ago

Fixes bug where changes were applied to the original flags objects from initialization. The object ldData.flags would retain a reference to the original flag set instead of being updated with the new merged object set in the change event.

In order to remediate this, we can grab the current state of the flags by passing a function to setLDData instead of an object.

For example, given this initial state:

flag1: on
flag2: off
flag3: off

After a changing flag2 to on:

flag1: on
flag2: on
flag3: off

After changing flag3 to on:

flag1: on
flag2: off <-- incorrectly set to original status!
flag3: on

Requirements

Related issues

Describe the solution you've provided

Provide a clear and concise description of what you expect to happen.

Describe alternatives you've considered

Provide a clear and concise description of any alternative solutions or features you've considered.