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

Different variants on server and client #18

Open
alexeyMohnatkin opened this issue Jan 29, 2017 · 24 comments
Open

Different variants on server and client #18

alexeyMohnatkin opened this issue Jan 29, 2017 · 24 comments
Labels

Comments

@alexeyMohnatkin
Copy link
Contributor

Server renders variant A, but client script can show variant B after rerender.
Also server always returns only one variant until restart. I think it happens because on first render server calls emitter.setActiveVariant and then always get this value even if there's another userIdentifier.
The solution is to check userIdentifier before calling emitter.getActiveVariant in getLocalStorageValue() in Experiment component.

@Akurganow
Copy link

Has the same problem

@durk0
Copy link

durk0 commented Apr 13, 2017

Same problem here

@diondirza
Copy link

diondirza commented Apr 27, 2017

got same problem even though I have set userIdentifier property. This error occured after I defined multiple experiment variants. Anyone has solved it?

@alexeyMohnatkin
Copy link
Contributor Author

alexeyMohnatkin@e2f338b
Not the best way, but it works. I just haven't much time to rewrite test and make PR.

@diondirza
Copy link

@alexeyMohnatkin thanks man, this work for now. You should make a PR for this. This issue really help isomorphic app.

@diondirza
Copy link

@alexeyMohnatkin I guess in my end this error still happen even using your patch.

@alexeyMohnatkin
Copy link
Contributor Author

@diondirza can you create sample project?

@peterpme peterpme added the bug label May 5, 2017
@peterpme
Copy link
Collaborator

peterpme commented May 5, 2017

@alexeyMohnatkin thanks so much for giving it a shot! Do you mind creating a pull request with whatever you have? We can work together to make it work 😄

@diondirza
Copy link

diondirza commented May 6, 2017

@alexeyMohnatkin sorry for late reply, been very busy this week. You can reproduce this error on my repo branch here. You need to retry several times with different browser or incognito mode to be able to reproduce the error.

@diondirza
Copy link

diondirza commented May 6, 2017

@peterpme Very glad to have this repo maintainer back. Do you able to update this repo so it supports latest react version? If you have time to look at my sample repo branch too, there is also a bug in server rendering about this

Warning: setState(...): Can only update a mounting component. This usually means you called setState() outside componentWillMount() on the server. This is a no-op. Please check the code for the Pushtell.CoreExperiment component.

Thoughts?

@alexeyMohnatkin
Copy link
Contributor Author

@diondirza I don't see any problems with variants. What behaviour do you expect?

@diondirza
Copy link

diondirza commented May 6, 2017

Persistent render result between client and server and I still got this issue on my console sometimes, try running with npm run develop
screen shot 2017-05-06 at 5 54 29 pm

@alexeyMohnatkin
Copy link
Contributor Author

@peterpme #24
@diondirza it seems that this is something wrong with your project, I can't reproduce this bug on my own

@alexeyMohnatkin
Copy link
Contributor Author

@diondirza try to rename Experiment 'menu' ;)

@diondirza
Copy link

@alexeyMohnatkin what's the problem with my experiment name?

@alexeyMohnatkin
Copy link
Contributor Author

Sorry, I haven't noticed that you use emitter.defineVariants(). This function causes the bug.

@alexeyMohnatkin
Copy link
Contributor Author

Actually it's your mistake. You call defineVariants before your app is rendered. Call it in DemoApp/index.js.

@diondirza
Copy link

@alexeyMohnatkin I have tried to remove that function in prod app, yet still facing it right now. I think it doesn't make sense that function cause the issue instead of on function that decides what variant to be rendered. Anyway thanks for your help.

@durk0
Copy link

durk0 commented Jun 20, 2017

Any progress guys?

@wehriam
Copy link
Contributor

wehriam commented Jun 20, 2017

@durk0 can you fork and create a test case that reproduces the issue?

@alexeyMohnatkin
Copy link
Contributor Author

updated tests in pr

@alexeyMohnatkin
Copy link
Contributor Author

can anybody merge pull request?

@ImanMh
Copy link

ImanMh commented Feb 12, 2018

pr is merged but I still have the same issue.

@stevecaldwell77
Copy link

stevecaldwell77 commented Mar 19, 2018

FWIW, I wrote a wrapper component to make sure my experiment only gets rendered client-side, so I can use this package in Gatsby. Otherwise I was seeing a flash of one variant (whichever one was chosen when Gatsby pre-built the page), and then to another (whichever ended up getting chosen when rendered in the browser).

Here it is:

import React from "react";
import Experiment from "react-ab-test/lib/Experiment";

export default class extends Experiment {
    constructor(props) {
      super(props);
      this.state = { inBrowser: false };
    }
    componentDidMount() {
        this.setState({ inBrowser: true });
    }
    render() {
        const { inBrowser } = this.state;
        return inBrowser
            ? <Experiment {...this.props} />
            : null;
    }
}

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

No branches or pull requests

8 participants