Description
Describe the bug
I'm using the React Native SDK and monitoring flag updates with the client.on('change', ...)
event. This event is called more times than the respective identify()
calls.
I'm aware I should be using useBoolVariation()
but for internal reasons I can't use that.
To reproduce
I've created this repo to reproduce this: https://github.com/tiagoalves/launchdarkly-issue
Instructions are in the README. I've shared our Mobile Client id with your support team.
This is the typical behaviour I'm seeing:
identify(A)
on('change', ...)
called for context A (as expected)identify(B)
on('change', ...)
called for context B (as expected)on('change', ...)
called for context A (unexpected)on('change', ...)
called for context B (unexpected)
Sometimes change
is only called twice (as expected). Sometimes 3 times, 4 times or more.
I've also resorted to using a promise chain for the consecutive identify()
calls but even that didn't help.
Expected behavior
I'd expect the change
event to exactly match the identify()
calls.
identify(A)
on('change', ...)
called for context Aidentify(B)
on('change', ...)
called for context B
Logs
In the logs we can see when the identify
promise chain is started (LdTest calling identify
log) which leads to two consecutive identify
calls. This leads to two expected change
triggers (LdTest ON CHANGE
logs). But then two more change
are received reverting the correct flag evaluation.
(NOBRIDGE) LOG LdTest MiCA Banner value: {"reason": "LD client not initialized", "value": false}
(NOBRIDGE) LOG LdTest MiCA Banner value: {"reason": {"errorKind": "USER_NOT_SPECIFIED", "kind": "ERROR"}, "value": false}
(NOBRIDGE) LOG LdTest calling identify
(NOBRIDGE) LOG LdTest ON CHANGE {"deployment": {"key": "unknown", "kind": "deployment", "timestamp": -1}, "kind": "multi", ... "user": {"country": "UNDEFINED", "custom": {"country": "UNDEFINED", "deviceId": "7964fa47-f9c3-44a6-9541-3ea1eb055134", "state": "UNDEFINED"}, "key": "anonymous", "kind": "user"}}
(NOBRIDGE) LOG LdTest MiCA Banner value: {"reason": null, "value": true}
(NOBRIDGE) LOG LdTest ON CHANGE {"deployment": {"key": "unknown", "kind": "deployment", "timestamp": -1}, "kind": "multi", ... "user": {"country": "UNDEFINED", "custom": {"country": "UNDEFINED", "deviceId": "7964fa47-f9c3-44a6-9541-3ea1eb055134", "state": "UNDEFINED"}, "key": "anonymous", "kind": "user"}}
(NOBRIDGE) LOG LdTest MiCA Banner value: {"reason": null, "value": false}
(NOBRIDGE) LOG LdTest ON CHANGE {"account": {"accountId": "f127648c-1532-4f39-aafb-66576272aee7", ..., "user": {"country": "PRT", "custom": {"accountId": "f127648c-1532-4f39-aafb-66576272aee7", "accountName": "AccountName", "country": "PRT", "deviceId": "7964fa47-f9c3-44a6-9541-3ea1eb055134", "organizationId": "880802a8-234f-44b6-9bca-c27c2d4fe693", "organizationName": "OrgName", "state": "UNDEFINED"}, "email": "user@example.com", "isNew": false, "key": "f9b59c77-99bc-4fdd-9548-54508d3cf2d5", "kind": "user"}}
(NOBRIDGE) LOG LdTest MiCA Banner value: {"reason": null, "value": true}
SDK version
10.10.0
Language version, developer tools
- React Native: 0.76.9
- Expo: 52.0.46
- TypeScript: 5.3.3
OS/platform
macOS 15.4.1
Additional context
All of this works as expected using the regular JS SDK. Seems to just be a problem with the React Native SDK.