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 causing destroy #623

Closed
arolson101 opened this issue Feb 6, 2016 · 15 comments · Fixed by #3506
Closed

hot reload causing destroy #623

arolson101 opened this issue Feb 6, 2016 · 15 comments · Fixed by #3506

Comments

@arolson101
Copy link

I'm using webpack-dev-server and I have hot reload working, but my form data gets destroyed because componentWillUnmount is called. From what I can gather from the hot loader demo unmount shouldn't be called. Is this expected, or have I hooked things up wrong?

Here is the callstack:

destroy (actions.js:23)
(anonymous function) (bindActionData.js:22)
(anonymous function) (bindActionCreators.js:14)
componentWillUnmount (createHigherOrd…mponent.js:115)
ReactCompositeComponentMixin.unmountComponent (ReactCompositeComponent.js:243)
ReactReconciler.unmountComponent (ReactReconciler.js:52)
ReactCompositeComponentMixin.unmountComponent (ReactCompositeComponent.js:246)
ReactReconciler.unmountComponent (ReactReconciler.js:52)
ReactCompositeComponentMixin.unmountComponent (ReactCompositeComponent.js:246)
ReactReconciler.unmountComponent (ReactReconciler.js:52)
ReactCompositeComponentMixin.unmountComponent (ReactCompositeComponent.js:246)
ReactReconciler.unmountComponent (ReactReconciler.js:52)
ReactChildReconciler.unmountChildren (ReactChildReconciler.js:115)
ReactMultiChild.Mixin.unmountChildren (ReactMultiChild.js:398)
ReactDOMComponent.Mixin.unmountComponent (ReactDOMComponent.js:911)
ReactReconciler.unmountComponent (ReactReconciler.js:52)
ReactChildReconciler.unmountChildren (ReactChildReconciler.js:115)
ReactMultiChild.Mixin.unmountChildren (ReactMultiChild.js:398)
ReactDOMComponent.Mixin.unmountComponent (ReactDOMComponent.js:911)
ReactReconciler.unmountComponent (ReactReconciler.js:52)
ReactCompositeComponentMixin.unmountComponent (ReactCompositeComponent.js:246)
ReactReconciler.unmountComponent (ReactReconciler.js:52)
ReactChildReconciler.unmountChildren (ReactChildReconciler.js:115)
ReactMultiChild.Mixin.unmountChildren (ReactMultiChild.js:398)
ReactDOMComponent.Mixin.unmountComponent (ReactDOMComponent.js:911)
ReactReconciler.unmountComponent (ReactReconciler.js:52)
ReactCompositeComponentMixin.unmountComponent (ReactCompositeComponent.js:246)
ReactReconciler.unmountComponent (ReactReconciler.js:52)
ReactCompositeComponentMixin.unmountComponent (ReactCompositeComponent.js:246)
ReactReconciler.unmountComponent (ReactReconciler.js:52)
ReactCompositeComponentMixin.unmountComponent (ReactCompositeComponent.js:246)
ReactReconciler.unmountComponent (ReactReconciler.js:52)
ReactCompositeComponentMixin.unmountComponent (ReactCompositeComponent.js:246)
ReactReconciler.unmountComponent (ReactReconciler.js:52)
ReactCompositeComponentMixin.unmountComponent (ReactCompositeComponent.js:246)
ReactReconciler.unmountComponent (ReactReconciler.js:52)
ReactCompositeComponentMixin._updateRenderedComponent (ReactCompositeComponent.js:567)
ReactCompositeComponentMixin._performComponentUpdate (ReactCompositeComponent.js:544)
ReactCompositeComponentMixin.updateComponent (ReactCompositeComponent.js:473)
ReactCompositeComponent_updateComponent (ReactPerf.js:66)
ReactCompositeComponentMixin.receiveComponent (ReactCompositeComponent.js:405)
ReactReconciler.receiveComponent (ReactReconciler.js:87)
ReactChildReconciler.updateChildren (ReactChildReconciler.js:84)
ReactMultiChild.Mixin._reconcilerUpdateChildren (ReactMultiChild.js:216)
ReactMultiChild.Mixin._updateChildren (ReactMultiChild.js:351)
ReactMultiChild.Mixin.updateChildren (ReactMultiChild.js:326)
ReactDOMComponent.Mixin._updateDOMChildren (ReactDOMComponent.js:871)
ReactDOMComponent.Mixin.updateComponent (ReactDOMComponent.js:700)
ReactDOMComponent.Mixin.receiveComponent (ReactDOMComponent.js:645)
ReactReconciler.receiveComponent (ReactReconciler.js:87)
ReactCompositeComponentMixin._updateRenderedComponent (ReactCompositeComponent.js:562)
ReactCompositeComponentMixin._performComponentUpdate (ReactCompositeComponent.js:544)
ReactCompositeComponentMixin.updateComponent (ReactCompositeComponent.js:473)
ReactCompositeComponent_updateComponent (ReactPerf.js:66)
ReactCompositeComponentMixin.receiveComponent (ReactCompositeComponent.js:405)
ReactReconciler.receiveComponent (ReactReconciler.js:87)
ReactCompositeComponentMixin._updateRenderedComponent (ReactCompositeComponent.js:562)
ReactCompositeComponentMixin._performComponentUpdate (ReactCompositeComponent.js:544)
ReactCompositeComponentMixin.updateComponent (ReactCompositeComponent.js:473)
ReactCompositeComponent_updateComponent (ReactPerf.js:66)
ReactCompositeComponentMixin.receiveComponent (ReactCompositeComponent.js:405)
ReactReconciler.receiveComponent (ReactReconciler.js:87)
ReactCompositeComponentMixin._updateRenderedComponent (ReactCompositeComponent.js:562)
ReactCompositeComponentMixin._performComponentUpdate (ReactCompositeComponent.js:544)
ReactCompositeComponentMixin.updateComponent (ReactCompositeComponent.js:473)
ReactCompositeComponent_updateComponent (ReactPerf.js:66)
ReactCompositeComponentMixin.receiveComponent (ReactCompositeComponent.js:405)
ReactReconciler.receiveComponent (ReactReconciler.js:87)
ReactCompositeComponentMixin._updateRenderedComponent (ReactCompositeComponent.js:562)
ReactCompositeComponentMixin._performComponentUpdate (ReactCompositeComponent.js:544)
ReactCompositeComponentMixin.updateComponent (ReactCompositeComponent.js:473)
ReactCompositeComponent_updateComponent (ReactPerf.js:66)
ReactCompositeComponentMixin.receiveComponent (ReactCompositeComponent.js:405)
ReactReconciler.receiveComponent (ReactReconciler.js:87)
ReactChildReconciler.updateChildren (ReactChildReconciler.js:84)
ReactMultiChild.Mixin._reconcilerUpdateChildren (ReactMultiChild.js:216)
ReactMultiChild.Mixin._updateChildren (ReactMultiChild.js:351)
ReactMultiChild.Mixin.updateChildren (ReactMultiChild.js:326)
ReactDOMComponent.Mixin._updateDOMChildren (ReactDOMComponent.js:871)
ReactDOMComponent.Mixin.updateComponent (ReactDOMComponent.js:700)
ReactDOMComponent.Mixin.receiveComponent (ReactDOMComponent.js:645)
ReactReconciler.receiveComponent (ReactReconciler.js:87)
ReactCompositeComponentMixin._updateRenderedComponent (ReactCompositeComponent.js:562)
ReactCompositeComponentMixin._performComponentUpdate (ReactCompositeComponent.js:544)
ReactCompositeComponentMixin.updateComponent (ReactCompositeComponent.js:473)
ReactCompositeComponent_updateComponent (ReactPerf.js:66)
ReactCompositeComponentMixin.performUpdateIfNecessary (ReactCompositeComponent.js:421)
ReactReconciler.performUpdateIfNecessary (ReactReconciler.js:102)
runBatchedUpdates (ReactUpdates.js:129)
Mixin.perform (Transaction.js:136)
Mixin.perform (Transaction.js:136)
assign.perform (ReactUpdates.js:86)
flushBatchedUpdates (ReactUpdates.js:147)
ReactUpdates_flushBatchedUpdates (ReactPerf.js:66)
Mixin.closeAll (Transaction.js:202)
Mixin.perform (Transaction.js:149)
ReactDefaultBatchingStrategy.batchedUpdates (ReactDefaultBat…Strategy.js:62)
enqueueUpdate (ReactUpdates.js:176)
enqueueUpdate (ReactUpdateQueue.js:24)
ReactUpdateQueue.enqueueForceUpdate (ReactUpdateQueue.js:143)
ReactComponent.forceUpdate (ReactComponent.js:86)
forceUpdateIfPending (deepForceUpdate.js:18)
traverseRenderedChildren (traverseRenderedChildren.js:4)
traverseRenderedChildren (traverseRenderedChildren.js:7)
deepForceUpdate (deepForceUpdate.js:33)
forceUpdateAll (requestForceUpdateAll.js:27)
@erikras
Copy link
Member

erikras commented Feb 9, 2016

Oooh, interesting. I am seeing this as well. It didn't used to do this. But it does not look like a redux-form bug. Maybe you should report this as an issue on the React Hot Loader repo?

@gaearon, is calling componentWillUnmount() on hot reload the new default behavior going forward, or is it a bug?

@gaearon
Copy link
Contributor

gaearon commented Feb 9, 2016

There is no new behavior, the repo has not been updated in months :-)
Please provide a project reproducing the issue. It is impossible to help based on a stack trace alone. Please publish a complete minimal example.

@erikras
Copy link
Member

erikras commented Feb 9, 2016

How I did it:

  1. Clone the redux-form docs
  2. npm install
  3. npm run dev
  4. Go to the Simple Form example
  5. Fill in some fields
  6. Modify src/examples/SimpleForm.js

It will hot reload and redux-form/DESTROY will be dispatched, which is only called in componentWillUnmount(), blowing away your form data.

It's not the most minimal example, but it's pretty simple to get running locally to replicate this issue.

@dlwalsh
Copy link

dlwalsh commented Mar 14, 2016

I'm having this issue with generic HMR as well.

If you're using HMR at the render point, as advocated in @gaearon's recent post, here's the workaround:

const store = configureStore();
const mountPoint = document.querySelector('[data-root]');

render(<Root store={store} />, mountPoint);

if (module.hot) {
  let persistentStore = store;
  module.hot.accept('src/Root', () => {
    const NextRoot = require('src/Root').default;
    persistentStore = configureStore(persistentStore.getState());
    render(<NextRoot store={persistentStore} />, mountPoint);
  });
}

@dlwalsh
Copy link

dlwalsh commented Mar 16, 2016

In fact there's an even simpler solution.

Just set destroyOnUnmount: !module.hot in the reduxForm() config.

@gaearon
Copy link
Contributor

gaearon commented Mar 16, 2016

Trying to reproduce this. Running npm run dev in 4.2.0 folder:

npm run dev

> redux-form-examples@ dev /Users/dan/p/redux-form/4.2.0
> node ./node_modules/better-npm-run dev

running better-npm-run in /Users/dan/p/redux-form/4.2.0
Executing script: dev

to be executed: node webpack/webpack-dev-server.js 
fs.js:584
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open './.babelrc'
    at Error (native)

Running it in the root doesn’t work either:

npm run dev
npm ERR! Darwin 15.0.0
npm ERR! argv "/usr/local/bin/iojs" "/usr/local/bin/npm" "run" "dev"
npm ERR! node v5.3.0
npm ERR! npm  v3.3.12
npm ERR! path /Users/dan/p/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open '/Users/dan/p/package.json'

@erikras
Copy link
Member

erikras commented Mar 16, 2016

@gaearon Sorry that directory structure has changed in the interim. I've fixed it. Try again, in the 4.2.0 folder. Still shows the same behavior.

@eliseumds
Copy link
Contributor

Any updates on this? Does it make sense to have destroyOnUnmount: !module.hot as default when NODE_ENV=development?

@mmazzarolo
Copy link

Hey guys, any news on this issue? Is destroyOnUnmount: !(__NODE_ENV__ === 'development' && module.hot) still the best solution?

@sunnysingh
Copy link

Is there a reason the commit that fixed this issue no longer exists in v6.3.2? 0b8dd94#diff-d749bb1257f721af37259e0346e623be

I'm currently using the destroyOnUnmount fix but there is no way to specify this globally (as far as I am aware of) so it seems hacky to add this option to every wrapped form.

@adorum
Copy link

adorum commented Apr 7, 2017

Hi, any news why 0b8dd94#diff-d749bb1257f721af37259e0346e623be was reverted and is gone from master?

@mojo5000
Copy link

mojo5000 commented Apr 29, 2017

I think this is what has been screwing me up. I'm using redux-form in a next.js project and have been tearing my hair out while my state disappears automagically with a hot reload... is this going to be put back in?

Per this thread it was removed: #947

@gustavohenke
Copy link
Collaborator

I'm closing this one as a duplicate of #2826 and #3005.
Please let's continue the discussion in #3005, since most of the information here don't apply anymore.

@erikras
Copy link
Member

erikras commented Oct 25, 2017

Fix published in v7.1.2.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants