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

NextJS Rendering #22

Open
joselevelsup opened this issue Oct 12, 2020 · 9 comments
Open

NextJS Rendering #22

joselevelsup opened this issue Oct 12, 2020 · 9 comments

Comments

@joselevelsup
Copy link

Table of Contents

Expected Behavior

The Experiment should render one variation and it should be displayed properly

Setup:

<Experiment name="An Experiment" userIdentifier={this.props.sessionId}> - sessionId comes from express-session
  <Variant name="Variation A">
    <div>
     {children} - children here represent actual elements not like a parent Component
    </div>
  </Variant>
  <Variant name="Variation B">
    <div>
     {children} - children here represent actual elements not like a parent Component
    </div>
  </Variant>
</Experiment>

Current Behavior

The Experiment does render a variation but it does not render the proper elements and its children.

Outcome:

{/* Rendered Properly */}
<div className="class">
 <p className="class-p">
  Hello P
</p>
 <p className="class-pd">
  Hello PD
</p>
</div>

{/* Current Results */}
<div className="class">
 <p className="class-p">
  Hello PD
</p>
 <p className="class-pd">
  Hello P
</p>
</div>

Possible Solution

Steps to Reproduce (for bugs)

  1. Start a new nextjs project
  2. Make a new Experiment in a page
  3. Add the sessionId from express-session to the Experiment userIdentifier prop
  4. See the results

Context

I can not show different variants properly if the rendering keeps breaking.

Your Environment

  • Version used: 2.3.0
  • Browser Name and version: Chrome 86.0.4240.75 or Firefox 81
  • Operating System and version (desktop or mobile): Manjaro
  • Link to your project: Can not provide.
@gregegan
Copy link

Experiencing the same issue

@gregegan
Copy link

FYI - I started dynamically importing the module and it looks to be rendering properly now.

https://nextjs.org/docs/advanced-features/dynamic-import

const DiscoveryFeed = dynamic(() => import('../DiscoveryFeed'), {
  ssr: true
});

@joselevelsup
Copy link
Author

@gregegan is it still working for you? Cause after a couple of refreshes (without dynamic imports), the problem I described would still occur. So I just want to make sure that with dynamic imports it works.

@gregegan
Copy link

I got it working properly with dynamic imports, yes.....

The serverside render definitely renders different markup then the clientside... so just dynamically importing it forces it to only clientside render.

@joselevelsup
Copy link
Author

@gregegan one last thing. Have you had it working without dynamic imports? Like just have the Variants render regular components.
e.g.

<Variant name="A">
  <div>
//Other elements in here
  </div>
</Variant>
<Variant name="B">
  <div>
//Other elements in here
  </div>
</Variant>

@gregegan
Copy link

I never got it working properly without dynamic imports, I was experiencing the same issue as you.

@joselevelsup
Copy link
Author

Ah. So thats where I am stuck.

@MauricioParadaG
Copy link

Solve it the same way. Thank you @gregegan it was the solution to use dynamic import

@moretti
Copy link
Member

moretti commented May 29, 2021

I created an example here:
https://github.com/marvelapp/react-ab-test/tree/master/examples/next
with server side rendering in NextJS.
The user identifier is just a UUID stored in the current session:

async ({ req }) => {
abTestsEmitter.rewind();
let userIdentifier = req.session.get('id');
if (!userIdentifier) {
userIdentifier = UUID();
req.session.set('id', userIdentifier);
await req.session.save();
}
return {
props: {
userIdentifier,
},
};

Let me know if that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants