Skip to content

Issues with SSR since @optimizely/react-sdk@^2.0.0 #87

Closed
@oMatej

Description

@oMatej

I am trying to integrate @optimizely/react-sdk with a project that uses the next.js framework. Everything was working fine, but since the release of @optimizely/react-sdk@^2.0.0 there is a problem with the initialization of optimizely instance on the client-side.

Even though I am providing the datafile that is fetched during server-side rendering, optimizely.isReady() initially returns false.

So my experiments that are defined like below:

<p>Experiments:</p>
<OptimizelyExperiment experiment="DEV_experiment">
  {variation => <p>got variation {variation}</p>}
</OptimizelyExperiment>
<hr/>
<OptimizelyExperiment experiment="DEV_experiment">
  <OptimizelyVariation variation="variation_1">
    variation_1
  </OptimizelyVariation>
  <OptimizelyVariation variation="variation_2">
    variation_2
  </OptimizelyVariation>
  <OptimizelyVariation default>
    default
  </OptimizelyVariation>
</OptimizelyExperiment>

During the server-side render the content for variation_2.

<p>Experiments:</p><p>got variation <!-- -->variation_2</p><hr/>variation_2</div>

But in the browser, it cannot retrieve it for some reason.

<p>Experiments:</p><p>got variation </p><hr>default</div>

Instead, I can see logs in the console that Client became ready (https://github.com/optimizely/react-sdk/blob/master/src/hooks.ts#L132). However, since I provided datafile, should not the client be ready right after initialization?

To Reproduce

You can use this repository to see the issue: https://github.com/oMatej/nextjs-optimizely

I think it can be something related to: #58

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions