react-sdk
react-sdk copied to clipboard
[BUG] useFeature returns false directly when the return datafile indicates true
Is there an existing issue for this?
- [x] I have searched the existing issues
SDK Version
"@optimizely/react-sdk": "^3.2.2",
Current Behavior
I'm using useFeature hook to get the feature flag and later use react query to call diff endpoint per feature flag setting.
When the component renders, I get isEnabled returned from the hook as false but later on all true. The setting on the Optimizely end for the flag is true and I can see it from the returned datafile as well.
I also tried to use clientReady, but it was true ever since component rendered.
Is this the default behaviour? I'm expecting isEnabled to be undefined while the client sdk is processing the datafile to get the isEnabled state.
Thanks,
Expected Behavior
useFeature hook should return undefined while processing
Steps To Reproduce
just use useFeature hook for a specific feature
React Framework
"react": "^18.3.1",
Browsers impacted
No response
Link
No response
Logs
No response
Severity
No response
Workaround/Solution
No response
Recent Change
No response
Conflicts
No response
Hey @yslkmart. Here are my findings on this -
clientReadyshould not be ready from the beginning. And we made some changes regarding that. #285. v3.2.3 contains the change. You are one patch short from that.useFeatureis designed this way from the beginning. If the client is not ready, it returnsfalseas a default. I can understand why that could be misleading. So Your proposal on usingundefinedinstead offalsemight be a better idea. But I don't see it as a bug necessarily. It could be an enhancement request. I have created an internal ticket FSSDK-11245 to track this.
Thanks for the issue!
@junaed-optimizely Thanks for the reply. I'm using ^3.2.2 so I think I'm actually using v3.2.3? but still clientReady is instantly true when component renders while isEnabled is false and in the datafile it's true.
So it sounds like getting isEnabled as false initially from useFeature is by design? In our case, we actually want three states for isEnabled i.e undefined when client is not ready, true and false when it is. Is there an existing workaround where we know when the client is not ready? clientReady doesn't seem to work. Currently, we just wait for a sec before reading isEnabled.
Thanks,
@yslkmart yes, in that case you are using 3.2.3. In that case you might be waiting for the client to get ready before rendering the component.
Either way, I think isEnabled should be undefined ( not false) while the SDK is calculating..