question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component wrapped in reduxForm gets unmounted on HMR

See original GitHub issue

Hello, i’m working on new react + redux + typescript + webpack2 starter kit. I’m using the react-hot-loader 3 beta for HMR which works fine… all my components that do not use redux-form get hot replaced without reloading the module or unmounting the component from DOM. Once i wrap the component in reduxForm to sync form state into the redux, unfortunately my component stops hot reloading correcly - every hot update unmounts and mounts component to the DOM.

What is the current behavior?

HMR unmounts component wrapped in reduxForm

What is the expected behavior?

HMR should not unmount component

Sandbox Link

I’ve created a branch of my project where you can reproduce the issue: git clone -b hmr-repro https://github.com/butchyyyy/arbes_react_poc yarn install yarn start open https://localhost:8080 Make a change to the BankAcountContainer.tsx => Hot update performed without unmounting the component Click “Add Payment Order” button next to the bank account, fill some value into the form and make a change to AddPaymentOrderContainer.tsx => Hot update performed with unmounting and mounting back the component emmiting destroy and loosing the from state in redux store.

What’s your environment?

Library versions: https://github.com/butchyyyy/arbes_react_poc/blob/hmr-repro/package.json Node 6.10.3 Windows 8.1 Pro Google chrome: 58.0.3029.110 (64-bit)

Other information

I’ve tried various changes to my setup, but the problem was still there. Unfortunately this is beyond my js knowledge so i don’t know if it’s redux-form, react-hot-loader or webpack problem, but the HMR works fine for everything but components wrapped in redux-form

I’ve tried to isolate the issue and in found out that in react-dom/lib/shouldUpdateReactComponent.js, at the line return nextType === 'object' && prevElement.type === nextElement.type && prevElement.key === nextElement.key; this comparision returns false prevElement.type === nextElement.type

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
Memfisraincommented, Nov 23, 2017

@erikras Hello, I’ve updated to 7.1.2 version and it seems like component with redux-form wrapper still unmounted. Could you send a link to working example? Thank you

3reactions
butchyyyycommented, Jun 20, 2017

That was imho more of a workaround than fix, you can do that via form configuration like this:

const form = reduxForm({ form: "someForm", destroyOnUnmount: module.hot ? false : true })(SomeForm)

Problem i see with this is that the app wil behave differently in prod / dev mode. While it “fixes” the problem of loosing data on hot module replacement, it introduces another problem of data not being destroyed when you unmount the component by e.g. navigating to another view => you have to somehow handle form reset in dev mode when you navigate back.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Component wrapped in reduxForm gets unmounted on HMR · Issue ...
Hello, i'm working on new react + redux + typescript + webpack2 starter kit. I'm using the react-hot-loader 3 beta for HMR which...
Read more >
redux-form is Destroying my state once the component is ...
The form's state subtree is destroyed when the form is unmounted, by design. This is the default and expected behaviour. From v6.2.1 onwards...
Read more >
How to Hot-Load React Component in 7 days. Part 2(React)
And trigger unmount/mount on all nesting tree. Not the thing you need. For example it will reset redux-form.
Read more >
reduxForm(config:Object)
a function that takes all the form values, the dispatch function, the props given to your component and the current blurred field, and...
Read more >
List of top ReactJS Interview Questions & Answers
Props get passed to the component similar to function parameters ... the component is not needed and gets unmounted from the browser DOM....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found