optimizely / react-sdk

React SDK for Optimizely Feature Experimentation and Optimizely Full Stack (legacy)
https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/javascript-react-sdk
Apache License 2.0
88 stars 33 forks source link

how do you supply a decision from server-side rendering to client-side rendering? #185

Open iamstarkov opened 1 year ago

iamstarkov commented 1 year ago
  1. I run createInstance on both server and client to get optimizely client.
  2. I run client.setUser({ id: userId }) with the same user id and attributes on both server and client.
  3. I use <OptimizelyProvider optimizely={client} user={{ id: userId }}> and both server (with isServerSide prop) and client.
  4. I use useDecision hook on both server and client and use the derived decision to render true or false if feature flag is disabled or not.
  5. Sometimes I get the mismatch between SSR and CSR.

I have tried to run client.decideAll() to get serialisable decisions on the server and tried to supply it to client-side created instance of the client, but I could not find a way to do it. Can you help?

mikechu-optimizely commented 1 year ago

Hi @iamstarkov,

Let me research on this and speak with one of the JS devs specifically.

mikechu-optimizely commented 3 months ago

Relates to #186

tareqlol commented 3 weeks ago

Hey @mikechu-optimizely, Any updates on this?

mikechu-optimizely commented 1 week ago

@junaed-optimizely Can we pair up on SSR & CSR when you're back from holiday? DM me please 😄

mikechu-optimizely commented 1 week ago

We have a work epic (series of tickets) to create a starter-kit or examples for CSR, SSR, and hybrid. We have already identified some rough edges that we want to provide guidance around or software updates to resolve. We'll start the first of these tickets in an upcoming sprint to show reference implementations. Please stay tuned.