Affected: JavaScript client-side SDK
Symptoms
The following error occurs when first implementing or updating event handlers:
ldclient.on('ready')
Cause
This happens when calling initialize first, then listening for the ready event after the SDK finished initializing. The ready event is only triggered once, and if you hook the ready event after it’s already been triggered, the callback will never be called because the event won’t occur again.
Solution
Use one of the following approaches:
Move the ready Listener Immediately After initialize
- Place the code that attaches the
readylistener immediately after calling theinitializefunction before the SDK has finished initializing. This ensures that your listener is in place to capture thereadyevent as soon as it occurs.
Use the waitUntilReady Promise
- Alternatively, you can use the
waitUntilReadypromise. This promise will resolve if the SDK is ever initialized instead of resolving only once. By using this approach, you can avoid missing thereadyevent due to timing issues during initialization.