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

Hot reload does not preserve component state #181

Closed
trueter opened this issue Sep 10, 2015 · 2 comments
Closed

Hot reload does not preserve component state #181

trueter opened this issue Sep 10, 2015 · 2 comments

Comments

@trueter
Copy link
Contributor

trueter commented Sep 10, 2015

Hey folks

I stumbled across this today.

To reproduce: Clone from master, npm install.

  • Add these to the Widgets View
 constructor(){
    super()
    this.state = {
      n: 0
    }
  }
  componentWillUnmount(){
    console.log("unmmount")
  }
  componentWillUpdate(){
    console.log("update")
  }
  • Some logging output to the top of the render function:
console.log(this.state.n);
  • And this to the render as e.g. as first child of the containing div.
<button onClick={ () => this.setState({ n : this.state.n + 1}) }>Update State</button>

When clicking the button the state is properly modified and the component re-renders. Each of these times componentWillUpdate is called. The issue appears when e.g. modifying the render function afterwards. Changing anything does trigger a hot reload, but afterwards the component does not update but unmounts and remounts. This calls the constructor and the state eventually gets reset.

As far as I know the component should not unmount. Someone on IRC suggested this might be related with a keying issue further up the tree, but I was not able to notice any differences in the react-ids in the DOM.

Thank you for providing this boilerplate and looking into this.

Cheers
Torsten

@erikras
Copy link
Owner

erikras commented Sep 10, 2015

I've made a branch to investigate this.

@trueter
Copy link
Contributor Author

trueter commented Sep 17, 2015

Looks like this got fixed in the process of 91cfa1e
Thanks @stevoland!

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

2 participants