Description
openedon Apr 12, 2017
Description
Connected component gets disconnected from store when code changed and applied by HMR.
Steps:
- fetch demo repo: https://github.com/hoschi/bare-minimum-react-hot-rr4-redux/tree/disconnected-component
- start dev server and open site in browser: http://localhost:8080/page2
- use 'Increment' button to increment counter state to 6
Expected behavior
Remove <p>test</p>
and 'Increment' component should receive changed state when clicked on one of the buttons.
Actual behavior
When I remove <p>test</p>
HMR does its code updating which leads to the problem that 'Increment' component doesn't get new store state. You can click on the buttons and the counter stays the same. I can see the actions dispatched in Redux devtools.
I found out that this is the case when the component above in the hierarchy is a container component which subscribed to state which is not subscribed in other components in the tree. You don't get the problem when you change
https://github.com/hoschi/bare-minimum-react-hot-rr4-redux/blob/08740ca8bac9a2d2d7e7527346f0ae36dde3234e/src/components/AppBarDesktopContainer.jsx
to:
import { connect } from 'react-redux';
import AppBarDesktop from './AppBarDesktop';
export default connect((state) => ({
newsData:state.counter
}))(AppBarDesktop);
and do the same steps described in the Description part.
Environment
react-redux 5.0.4, I tried also 5.0.2 and 5.0.3 without effect
https://github.com/hoschi/bare-minimum-react-hot-rr4-redux/blob/08740ca8bac9a2d2d7e7527346f0ae36dde3234e/package.json
Run these commands in the project folder and fill in their results:
node -v
: 6.3.1npm -v
: 3.10.3
Then, specify:
- Operating system: Linux (Arch)
- Browser and version: Chrome, 56.0.2924.87 (64-bit)
Reproducible Demo
https://github.com/hoschi/bare-minimum-react-hot-rr4-redux/tree/disconnected-component
Probably related issues
- react-redux 5.0.2 to 5.0.3 update break hot reloading gaearon/react-hot-loader#492
- react-redux 5.0.3 breaks hot-reloading #636
- Redux store unconnect gaearon/react-hot-loader#539
fun fact: You have to delete the tag below, deleting one above will trigger this bug and 'fixes' the one I'm reporting here.