adopted-ember-addons / ember-launch-darkly

A modern Ember addon to wrap the Launch Darkly service
MIT License
13 stars 24 forks source link

_client can be null causing type error #123

Closed chrisvdp closed 4 years ago

chrisvdp commented 4 years ago

We are calling this.launchDarkly.variation('feature-flag') within our code (the application controller), but based on network timing the client onReady event may not have fired yet. This means that the current value of _client on https://github.com/ember-launch-darkly/ember-launch-darkly/blob/df0bd2567d896702cde8b6799902b0e4ba177324/addon/services/launch-darkly-client-remote.js#L61 is null, causing a TypeError:

launch-darkly-client-remote.js:62 Uncaught TypeError: Cannot read property 'variation' of null
    at Class.variation (launch-darkly-client-remote.js:62)
    at Proxy.variation (launch-darkly.js:36)
    at Class.<anonymous> (application.js:77)

Ideally, the service would defend against _service as null, possibly by init'ing it to nullClient

chrisvdp commented 4 years ago

According to the docs, it seems that bootstrapping https://docs.launchdarkly.com/sdk/client-side/javascript#bootstrapping might help, but I don't see any documentation on this. Is this something that this addon supports?

chrisvdp commented 4 years ago

I was able to fix this in a fork with an updated launch darkly client. Version 2.10.0 of the launch darkly SDK allows for anonymous users which means I can ensure that the client is initialized sooner