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
ready
listener immediately after calling theinitialize
function before the SDK has finished initializing. This ensures that your listener is in place to capture theready
event as soon as it occurs.
Use the waitUntilReady
Promise
- Alternatively, you can use the
waitUntilReady
promise. This promise will resolve if the SDK is ever initialized instead of resolving only once. By using this approach, you can avoid missing theready
event due to timing issues during initialization.