-
Notifications
You must be signed in to change notification settings - Fork 37
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
fix: Hooks gracefully return with an error message when optimizely prop is null #154
Conversation
@@ -1,5 +1,5 @@ | |||
/** | |||
* Copyright 2018-2019, Optimizely | |||
* Copyright 2022, Optimizely |
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.
2018-2019, 2022
src/hooks.ts
Outdated
if (!optimizely) { | ||
throw new Error('optimizely prop must be supplied via a parent <OptimizelyProvider>'); | ||
hooksLogger.warn(`Unable to use decision ${flagKey}. optimizely prop must be supplied via a parent <OptimizelyProvider>`); |
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.
Move conditional above overrideAttrs
src/hooks.ts
Outdated
hooksLogger.warn(`Unable to use decision ${flagKey}. optimizely prop must be supplied via a parent <OptimizelyProvider>`); | ||
return [ | ||
createFailedDecision(flagKey, 'Optimizely SDK not configured properly yet.', { | ||
id: overrides.overrideUserId || null, |
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.
Return null for user items bc user depends on Optimizely object
@zashraf1985 - let me know when you get a chance to review. Thanks in advance! |
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.
Looks Great! Can you change the PR description format to what we usually use like "Summary", "Test Plan" etc.
Summary
Enables usage of hooks within the Optimizely Provider without passing in the
optimizely
prop.Previously, attempting to use hooks within an Optimizely Provider with a missing
optimizely
prop led to an error being thrown resulting in a crash.With this change, hooks now return pessimistic results when the
optimizely
prop isnull
.Addresses this issue:
Also related:
Note:
optimizely
prop is null.Test Plan
Refactored tests that expect hooks to throw errors when Optimizely provider is not present.