Skip to content
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

[BUG] OptimizelyProvider overwrites user set via setUser with default user unless passed via user prop #286

Closed
1 task done
dnedo opened this issue Oct 26, 2024 · 2 comments
Labels
acknowledged bug Something isn't working needs-triage

Comments

@dnedo
Copy link

dnedo commented Oct 26, 2024

Is there an existing issue for this?

  • I have searched the existing issues

SDK Version

3.2.2

Current Behavior

After upgrading to v3 of the Optimizely React SDK, rendering OptimizelyProvider after setting a user via setUser overwrites the previously set user with a default one, unless the user is explicitly passed to the provider via the user prop.

Expected Behavior

In our app, we handle Optimizely initialization and set the correct user ID and attributes outside the React lifecycle. Some of our initial decision calls may occur before the React tree is rendered, which is why we call setUser as early as possible. Our user object is also independent of the React lifecycle, which is why we've avoided passing it directly to the provider.

Is managing user outside of the React lifecycle not supported anymore? We would expect OptimizelyProvider to respect the previously set user and avoid overwriting it if the client already has a user set.

Steps To Reproduce

const optimizelyClient = createInstance({ sdkKey: "key" });

optimizelyClient.setUser({ id: "unique_id", attributes: { a: 1, b: 2 } });

// at this point, inspecting optimizelyClient.user shows the values have been set correctly
console.log(optimizelyClient.user);

function App() {
  useEffect(() => {
    // at this point, inspecting optimizelyClient.user shows the previously set values have been overwritten by OptimizelyProvider
    console.log(optimizelyClient.user);
  }, []);

  return (
    <OptimizelyProvider client={optimizelyClient}>
      <AppContent />
    </OptimizelyProvider>
  );
}

React Framework

react-native 0.74.5

Browsers impacted

No response

Link

No response

Logs

No response

Severity

Blocking development, Affecting users

Workaround/Solution

Add an additional check to the final else branch inside OptimizelyProvider's setUserInOptimizely method here:

} else {
that would prevent it from falling back to the default user if there's already a non-default user set in the client.

Recent Change

#229

Conflicts

No response

@dnedo dnedo added bug Something isn't working needs-triage labels Oct 26, 2024
@junaed-optimizely
Copy link
Contributor

@dnedo, you are correct. This is not expected behavior. I have created internal ticket (FSSDK-10880) to track this.

I will get back to it, when I will have some updates.

Thanks!

@junaed-optimizely
Copy link
Contributor

v3.2.3 is out with the fix!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledged bug Something isn't working needs-triage
Projects
None yet
Development

No branches or pull requests

2 participants