-
Notifications
You must be signed in to change notification settings - Fork 2
FFM-12129 Add onFlagNotFound to FFContextProviderProps
#22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/context/FFContext.tsx
Outdated
| const [clientInstance, setClientInstance] = | ||
| useState<FFContextValue['client']>() | ||
|
|
||
| // Use a reference to keep track of the latest loading state, allowing access to its current value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using the loading state and passing it to the new onFlagNotFound option. But it would still be true and not false when the SDK initialised and onFlagNotFound was called. I think this is due to the state being updated async, so this is what I went with as an alternative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is that your handler is set in stone at the point it's created and so has the value of the state. This is because it's being defined in the useEffect, which isn't being recalled when the loading state changes. The ref is a cleaver way of getting the right value without triggering renders 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor stuff
src/context/FFContext.tsx
Outdated
| const [clientInstance, setClientInstance] = | ||
| useState<FFContextValue['client']>() | ||
|
|
||
| // Use a reference to keep track of the latest loading state, allowing access to its current value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is that your handler is set in stone at the point it's created and so has the value of the state. This is because it's being defined in the useEffect, which isn't being recalled when the loading state changes. The ref is a cleaver way of getting the right value without triggering renders 👍🏻
Apply suggestions from code review Co-authored-by: Kevin Nagurski <Kevin.nagurski@harness.io>
c6b9bd7 to
a5721a5
Compare
a5e0f2a to
ee6acba
Compare
6f9fbd6 to
7e320f6
Compare
e0f7a70 to
a3859cb
Compare
What
Adds a new optional prop called
onFlagNotFound, which is a callback that gets triggered whenever a variation is requested and the flag cannot be found. This prop receives two arguments:flagNotFound: A typeDefaultVariationEventPayloadfrom the Javascript SDK containing the flag identifier and the default variation that was served.loading: A boolean that indicates whether the SDK was still initializing at the time the variation call was made and the flag was not found.The mechanism for achieving this is listening to the new Javascript SDK event (as of 1.29.0)
ERROR_DEFAULT_VARIATION_RETURNEDwhich is fired by the Javascript SDK when a call tovariationhas returned the default variation.Why
Inform users when the SDK has served a default variation, for example, due to a flag typo, misconfiguration, or the SDK not being fully initialized. For cases where the SDK is not initialized, the user may choose not to care as this is the default behaviour in
asyncmode, and theloadingargument can be used to filter those out.Testing
Added new test suite for
FFContextManual
Using
useFeatureFlaghook:asyncdisabledonFlagNotFoundexecutes when the SDK has finished initialisingonFlagNotFounddoes not execute after the SDK initialisesasyncenabledonFlagNotFoundexecutes immediately, and again when the SDK initializes.onFlagNotFoundexecutes immediately, but does not execute after the SDK initiailises