0

This code has been working fine, but now it's working intermittently in chrome. Does anyone know what might be causing this. If so what can I do to increase stability in chrome

This function opens a pop up modal with the project form react component.

editProject: function(i) {
    $('#agency_projects').trigger(
            "projects:open", 
            [this.state.projects[i].showUrl, true]
    );
},

getInitialState: function() {
    return {

        ...

        /* TODO Refactor to prevent props in initialState */
        projectId:      this.props.projectId,
        projectUrl:     this.props.projectUrl,
    }
},

The initial state has the project id, and url stored which is used to submit an ajax request to pull in the project.

componentDidMount: function() {
    if(this.props.projectUrl) {
        $.getJSON(this.state.projectUrl)
        .done(function(data) {
            if(!this.isMounted()) {
                return;
            }
            this.setState({
                title:          data.title,
                externalUrl:    data.externalUrl,
                client:         data.client,
                description:    data.description,
                content:        data.content,
            });
        }.bind(this))
        .fail(function(jqXHR, status, err) {
            console.error(jqXHR, status, err);
        });
    }
},

The form renders as suspected, but the data is only pulled every now and again.

  • It looks right to me! Are there any errors in the console? Is it ever returning from the `isMounted` check? (You could add a `console.log` to check). Does it send the request for JSON, then not set state? Or does it skip the JSON request altogether? – rmosolgo Aug 31 '16 at 20:58
  • "Working intermittently" suggests a race condition on the `getJSON` callback. The deprecated use of `isMounted` looks fishy to me; you may want to try migrating away from it [as recommended](https://facebook.github.io/react/blog/2015/12/16/ismounted-antipattern.html) and see if that ends up fixing anything. Apart from that, I agree with @rmosolgo - sprinkle `console.log` statements all over this, and look at the network tab in the chrome dev tools, so you can figure out what the execution path is when it fails. – Chris Martin Sep 01 '16 at 04:07

0 Answers0