TrueCar / react-launch-darkly

Simple component helpers to support LaunchDarkly in your React app.
MIT License
76 stars 20 forks source link

Refactor ldClientWrapper initialization #25

Closed jacobmoretti closed 7 years ago

jacobmoretti commented 7 years ago

Problem

When using the LaunchDarkly component in a universal app, the rendering of LaunchDarkly may occur server-side. This poses a problem since ldclient-js is only for the browser. It uses XMLHttpRequest which is not available in node. For reference, this wasn't an issue prior to 0.0.9. However, in 0.0.9, we moved the client initialization into the LaunchDarkly component.

Solution

Moving the initialization of the client into the FeatureFlag component, we can ensure that the LaunchDarkly component can continue to be used at the top-most level in your component hierarchy.