Unleash / unleash-proxy-client-js

A browser client that can be used together with the unleash-proxy.
Apache License 2.0
44 stars 46 forks source link

Feature toggle correct value not reflecting right away after context Update #152

Closed coderscode2 closed 2 months ago

coderscode2 commented 1 year ago

Describe the bug

I have a feature toggle xyz and its value is true for userId 123.

Right after user logs in successfully, we update the context with userId. The xyz toggle value is still coming back as false even after userId update in the context. This is causing issues.

coderscode2 commented 1 year ago

@thomasheartman Can you please let me know if and when you have any update on this issue?

megancooper commented 1 year ago

For others experiencing this issue and using react, I found a workaround in the meantime by swapping the useFlag hook for directly accessing the flag value from the FlagsContext:

import {useFlag, FlagContext} from '@unleash/proxy-client-react';

-const myFlag = useFlag('flag-name');
+const {isEnabled} = useContext(FlagContext);
+const myFlag = isEnabled('flag-name');

The issue seems to be that the update event, which seems to be consistently emitting when its supposed to, sometimes fails to actually invoke the callback that the react library is using in the useFlag hook

daveleek commented 1 year ago

Hello @coderscode2! One question that came up as we were looking at this: are you awaiting the update of the context? It's an async method that communicates with the server, so it needs to be awaited

coderscode2 commented 1 year ago

@daveleek Yes, I am using await but it still returns incorrect value

daveleek commented 1 year ago

Ok thank you @coderscode2! we'll have a look!