cdebotton / react-universal

React, redux, react-router, graphql, postgres, koa, universal starter-kit
293 stars 27 forks source link

Not good behavior of HMR when update reducer file. #7

Closed nodkz closed 8 years ago

nodkz commented 8 years ago

Firstly I run vanilla app, and click 5 times on the HOME icon. react-universal-hmr-3

After that I open /app/reducers/app.js and change code:

  case INCREMENT_COUNTER:
    console.log('test');  // add this code, to check replay HMR all actions or not 
    return {
      ...state,
      counter: state.counter + 100,  // was + 1
    };

HMR works, and produce react-universal-hmr-4

I expect that counter does not change its value. And stays as 5. And if i click on the home icon it became 105, 205, etc.. But it became equal to 500.

How I understood, HMR has reinit state from scratch and replays all actions. But it is not good. Imagine, that we work with some DB, and some actions change data in DB. And if HMR replays actions from initial state it can get error from DB (record already exists, or record not found, because it was changed by actions at first time).

In such way, HMR does not give us ability to continue work with existed app state.

cdebotton commented 8 years ago

This actually seems to be an issue with the behavior of the babel hot module replacement plugin, as it is implemented and behaves as it should. I'm going to close this comment out for now, unless I'm misunderstanding the issue, then please let me know.