-
Notifications
You must be signed in to change notification settings - Fork 36
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
Circular structure of SDK client breaks next.js SRR #16
Comments
I do not think you should return the SDK client from So basically you would end up with something like this:
|
Sometimes you might want to return the SDK in Otherwise you might need to initialize the optimizely client multible times on the server (1 x for But there is a trick that allows you to reuse the instance on the server: // As soon as Next.js tries to serialize the client it will return null
optimizelyClientInstance = optimizely.createInstance()
optimizelyClientInstance.toJSON = () => null
return {
optimizelyClientInstance,
...pageProps
} So you can now return the client inside const WithOptimizely = ({ optimizelyClientInstance = optimizely.createInstance(), ...props }) => {
...
} |
We have the same issue. We are trying to use Optimizely Rollouts with Segment to get If we initialise this on the client -- it's too late, Segment has already loaded. I attempted to serialize the instance that we created on the server-side and pass it down on the window as a script. I believe this should resolve our issues, but alas, due to this circular structure we cannot. |
Internal Ticket [FSSDK-8658] |
We get a SDK client on the server by running createInstance({...})
Next.js serialize all objects to json when sending them to the client.
We then get
Error: Circular structure in "getInitialProps" result of page "/_error". https://err.sh/zeit/next.js/circular-structure
The reason is that the SDKClient has a circular structure whitch is not supported in JSON
TypeError: Converting circular structure to JSON
Creating on client at the server side and the create it again in the client browser leads to a flickering behavior, since we recreate the SDK client and the turned on feature temporary goes away until we load data in the newly created client
It would be great if you could you change your SDK client to not use circular structure, so it can be serialized.
Our created SDK client looks like this
The text was updated successfully, but these errors were encountered: