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

Order of middleware stack, and thunk #9

Closed
qnm opened this issue Aug 11, 2015 · 4 comments
Closed

Order of middleware stack, and thunk #9

qnm opened this issue Aug 11, 2015 · 4 comments

Comments

@qnm
Copy link

qnm commented Aug 11, 2015

I've been debugging an issue for the last while, and the crux of the issue is that thunk sat further down the middleware stack than it should, causing me some rather opaque errors.

In particular, devTools ran before it, and was throwing an exception as it tried to interpret the result returned from an action creator.

My fix involved changing from this

const finalCreateStore = compose(
  devTools(),
  applyMiddleware(thunk),
  persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/)),
  createStore
);

to this

const finalCreateStore = compose(
  applyMiddleware(thunk),
  devTools(),
  persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/)),
  createStore
);

Is it worthwhile stating on the README that thunk must be run before other middleware, or is this issue specific to devTools?

@gaearon
Copy link
Collaborator

gaearon commented Aug 13, 2015

From http://gaearon.github.io/redux/docs/api/applyMiddleware.html:

If you use other store enhancers in addition to applyMiddleware, make sure to put applyMiddleware before them in the composition chain because the middleware is potentially asynchronous. For example, it should go before redux-devtools because otherwise the DevTools won’t see the raw actions emitted by the Promise middleware and such.

But I agree it's not enough.
Can I ask you to contribute PR to amend README of redux-devtools to highlight this?

@qnm
Copy link
Author

qnm commented Aug 13, 2015

@gaearon Sure! I'll aim to get to it this week.

@gaearon
Copy link
Collaborator

gaearon commented Dec 13, 2015

Closing as inactive.

@dazlious
Copy link

dazlious commented Apr 18, 2018

see #173

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants