launchdarkly / js-client-sdk

LaunchDarkly Client-side SDK for Browser JavaScript
Other
112 stars 65 forks source link

React SDK client ignoring the `streaming` option #170

Closed cvetanov closed 5 years ago

cvetanov commented 5 years ago

Describe the bug The official docs state the following about the streaming option: "If true, the client will maintain a streaming connection to LaunchDarkly to receive feature flag changes as they happen. (default: false)" - note the "default: false" part.

To reproduce Scaffold a create-react-app and integrate the withLDProvider HOC without specifying options.streaming. You will end up with streaming of live updates to the flag, even though the docs say that by default this is false.

Expected behavior Do not stream live updates of the flag if the options.streaming is not explicitly set to true.

SDK version "launchdarkly-react-client-sdk": "^2.12.4" - latest at this point

Language version, developer tools "react": "^16.8.6" - latest at this point

OS/platform Not relevant

Additional context I did a bit of digging around and it seems that there is a change listener in the React SDK which messes up the shouldBeStreaming conditions in the core SDK. Here is the function in the React SDK which subscribes to changes, regardless of the options.streaming flag and it is always invoked here.

This change listener leads to consequences in the core SDK here.

The condition in the core SDK will be evaluated to true (options.streaming, or streamForcedState in that scope (assignment done here), is undefined and there is a subscription to changed events) and we will get live streaming of flag updates, even though the docs say that by default there is no streaming of flag updates.

I will be happy to submit a PR where the change listener will be added conditionally based on the options.streaming flag if you agree that is the expected behaviour.

bwoskow-ld commented 5 years ago

Hi @cvetanov ,

Thanks for pointing this out! The SDKs are actually functioning as designed: developers directly using the JS SDK (for example, through the launchdarkly-js-client-sdk package) are set to use polling by default, and developers using the React SDK are set to use streaming by default.

We took a look at the documentation and the streaming parameter description was misleading. It said that the default value was false but that was only true for those using the JS SDK directly. I went ahead and updated the documentation to be clearer.

If you want to use the React SDK in polling mode, you can set options.streaming to false.