Skip to content
This repository has been archived by the owner on Jul 31, 2018. It is now read-only.

Hot reloading reducers not supported? #72

Closed
shem86 opened this issue Apr 6, 2016 · 4 comments · Fixed by #85
Closed

Hot reloading reducers not supported? #72

shem86 opened this issue Apr 6, 2016 · 4 comments · Fixed by #85

Comments

@shem86
Copy link

shem86 commented Apr 6, 2016

Hi,
I'm changing todos 'add todo' reducer to set completed to true on creation and I get:

[HMR] Cannot apply update. Need to do a full reload!
dev-server.js:19 [HMR] Error: Expected the reducer to be a function. Instead got an object with a "default" field. Did you pass a module instead of the default export? Try passing require(...).default instead.

Tested on unmodified Todo app,
Any ideas?

@tj
Copy link
Owner

tj commented Apr 6, 2016

not sure, I've removed HMR from my apps entirely, seems buggy and I don't have the time to fix that stuff

@shem86
Copy link
Author

shem86 commented Apr 7, 2016

Seems like adding .default to require call for reducers on webpack HMR fixes it.

if (module.hot) {
    module.hot.accept('../reducers', () => {
      const nextReducer = require('../reducers').default
      store.replaceReducer(nextReducer)
    })
  }

Note that when using require if you want the default export you need to manually grab it through .default. Reason for this is require doesn’t handle both default and normal exports so you have to specify which to return. Whereas import has a system for this in place so it knows already (eg. import foo from 'bar') vs import {baz} from 'bar').

Taken from webpack-your-bags

@alanrsoares
Copy link
Contributor

@zirho
Copy link
Contributor

zirho commented Jul 13, 2016

I made a PR for this
#85

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.

4 participants