You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a timing bug in all three hooks' (useFeature, useExperiment, and useDecision) that leads to autoUpdate: true render triggers getting lost.
The code in #125 introduced a window of time between the mounting of the hook and the registering a listener for config or user changes. If the user (or presumably the config) is changed in that window of time, an update will not be triggered.
This pattern is used in all of the hooks.
useEffect(()=>{// Subscribe to update after first datafile is fetched and readyPromise is resolved to avoid redundant rendering.if(optimizely.getIsReadyPromiseFulfilled()&&options.autoUpdate){returnsetupAutoUpdateListeners(optimizely,HookType.FEATURE,featureKey,hooksLogger,()=>{setState(prevState=>({
...prevState,
...getCurrentDecision(),}));});}return(): void=>{};},[optimizely.getIsReadyPromiseFulfilled(),options.autoUpdate,optimizely,featureKey,getCurrentDecision]);
If the user is changed too soon, the listener will still be set up, but it will be too late. The change has already occurred and the decision has not be reassessed.
I would propose that, immediately before setting up the listener, the code must determine if the user or config has changed since the hook was mounted. If so, it should execute the setState code prior to setting up the listener. For example:
useEffect(()=>{// Subscribe to update after first datafile is fetched and readyPromise is resolved to avoid redundant rendering.if(optimizely.getIsReadyPromiseFulfilled()&&options.autoUpdate){if(userorconfighavechangedsincemounting){setState(prevState=>({
...prevState,
...getCurrentDecision(),}));}returnsetupAutoUpdateListeners(optimizely,HookType.FEATURE,featureKey,hooksLogger,()=>{// remainder is the same as before
The text was updated successfully, but these errors were encountered:
There is a timing bug in all three hooks' (
useFeature
,useExperiment
, anduseDecision
) that leads toautoUpdate: true
render triggers getting lost.The code in #125 introduced a window of time between the mounting of the hook and the registering a listener for config or user changes. If the user (or presumably the config) is changed in that window of time, an update will not be triggered.
This pattern is used in all of the hooks.
If the user is changed too soon, the listener will still be set up, but it will be too late. The change has already occurred and the decision has not be reassessed.
I would propose that, immediately before setting up the listener, the code must determine if the user or config has changed since the hook was mounted. If so, it should execute the
setState
code prior to setting up the listener. For example:The text was updated successfully, but these errors were encountered: