Redux-saga: Compare `END` action by string `type`, not by reference, to allow middleware-transformed actions

Created on 9 May 2016  Â·  3Comments  Â·  Source: redux-saga/redux-saga

Discovered during debugging of a weird saga hang issue here https://github.com/yelouafi/redux-saga/issues/304#issuecomment-217727607 – the sagas weren't terminating after dispatching the END action, even if they consisted only from fork and take effects.

The culprit was the middleware that timestamps all the actions (adds meta: { timestamp: 1234567890 }), but does this by re-creating the action objects as if they were immutable:

export default function actionTimestampMiddleware() {
  return () => (next) => (action) => {
    if (typeof action === 'object') {
      // Add `meta.timestamp` of the dispatch time to all action objects.
      const nextAction = {
        ...action,
        meta: {
          ...action.meta,
          timestamp: Date.now(),
        },
      };
      return next(nextAction);
    }
    return next(action);
  };
}

This changes the reference of the END action, which results in the action being unhandled inside the redux-saga. The internals compare the action by reference, not by the string action type, so the re-created action object doesn't pass the checks.

I found the following places where this may occur, but there may be more:

CC @yelouafi

bug

Most helpful comment

FYI fixed in 0.10.3

All 3 comments

Thanks for the catch. I'll fix this in the next patch

FYI fixed in 0.10.3

@yelouafi Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidwparker picture davidwparker  Â·  3Comments

Zacqary picture Zacqary  Â·  3Comments

Beingbook picture Beingbook  Â·  3Comments

NullVoxPopuli picture NullVoxPopuli  Â·  3Comments

neurosnap picture neurosnap  Â·  3Comments