-
Notifications
You must be signed in to change notification settings - Fork 37
Closed
Description
There are a few issues that make it impossible for the application to still work if optimizely fails to initialize:
optimizely.createInstance
fromoptimizely-sdk
can returnnull
https://github.com/optimizely/javascript-sdk/blob/v4.7.0/packages/optimizely-sdk/lib/index.browser.ts#L136createInstance
in thereact-sdk
does not handle thenull
case and then just throws in the constructor when accessingthis._client.onReady
https://github.com/optimizely/react-sdk/blob/2.7.0/src/client.ts#L195-L201- if we catch this thrown error in our application code, we cannot render
OptimizelyProvider
because it needs anOptimizelyReactSDKClient
instance
https://github.com/optimizely/react-sdk/blob/2.7.0/src/Provider.tsx#L27 - conditionally rendering the
OptimizelyProvider
is not an option because the optimizely hooks fromreact-sdk
throw when there is nooptimizely
instance provided via theOptimizelyProvider
https://github.com/optimizely/react-sdk/blob/2.7.0/src/hooks.ts#L332-L336 - the rules of hooks disallow to render hooks conditionally, so we cannot catch this issue on the application side
We currently see in production ~70.000 failed optimizely initializations / hour. All happening in Firefox, and we need to investigate more, but the main issue is that failing optimizely makes the application unusable, which is not a graceful fallback.
I have different ideas to solve this:
react-sdk
allows to renderOptimizelyProvider
withoptimizely={null}
and the optimizely hooks are modified to not throw anymore when nooptimizely
instance is available. Applications will need to catch the thrown error from the initialcreateInstance
call and as a fallback usenull
. The hooks then fall back to the same values they would when optimizely is not yet ready.react-sdk
does not throw increateInstance
whenoptimizely
isnull
and rather wraps all accesses tothis._client
with anull
check.react-sdk
provides aDummyReactClient
that implements all the functions fromReactSDKClient
with no functionality. Applications will need to catch the thrown error from the initialcreateInstance
call and as a fallback use theDummyReactClient
and provide it toOptimizelyProvider
.
I would vote for option 1. because it still allows applications to detect when createInstance
fails and allows for the maximum flexibility. Also it's backwards-compatible.
ivanngbowtie and zdivozzo
Metadata
Metadata
Assignees
Labels
No labels