Skip to content

Using @client and @resolve on the same class causes @resolve to be called twice #128

@liamzdenek

Description

@liamzdenek

Reproduction test case

import React, {Component} from 'react'; 
import { resolve, client } from "react-resolver";
import Promise from 'bluebird';

export class SearchPage extends Component {                                        
    render() {
        console.log("Re-Rendering: ", this.props.user);                               
        return <div>
            Prop: {this.props.user}
        </div>
    }
}
// uncomment this and you'll see "Waiting on response" and "Resolving" repeated twice in the console
/*
@client(() => {
    return <div>Loading...</div>
})
 */
@resolve({
    "user": function(props) {
        console.log("Waiting on response, ", props);
        return new Promise((resolve,reject) => {
            setTimeout(() => {
                console.log("Resolving");
                resolve("ayyyyyy");
            }, 5000)
        })
    }
})
export default class InnerSearchPage extends SearchPage {};

Expected Output
[with or without server side rendering, eg, React Router switching pages. This is the observed behavior without @client(...)]

Waiting on response,  Object { [abridged] }
Resolving
USER PROP:  ayyyyyy

Actual Output
[with or without server side rendering]

Waiting on response,  Object { [abridged] }
Resolving
USER PROP:  ayyyyyy
Waiting on response,  Object { [abridged] }
Resolving
USER PROP:  ayyyyyy

Notes

I'm using server-side rendering, but the behavior is unchanged when I remove window.__REACT_RESOLVER_PAYLOAD__.
I am using HOC as a parent of this component.
Some Versions. I don't know how much of this is relevant.

"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-redux": "^5.0.5",
"react-resolver": "^3.1.0",
"react-router": "^4.1.1",
"react-router-dom": "^4.1.1",
"redux": "^3.7.0",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions