rgommezz/react-native-offline

Saga side effect not being called after an action is auto dispatched from the `actionQueue` (When network state changes from offline to online)

kusalshrestha opened this issue · 4 comments

Current Behavior

The saga side effect is not invoked. However the action from the actionQueue is dispatched.
In my case:

  1. When online
  • dispatch FETCH_CUSTOMERS - OK
  • dispatch FETCH_CUSTOMERS_SUCCESS after api call - OK
  1. When network state changes from offline to online
  • dispatch FETCH_CUSTOMERS - OK
  • But it's side effect does not call. (i.e no api call happens)

Screen Shot 2021-07-08 at 11 12 04 AM

Screen Shot 2021-07-08 at 11 28 55 AM

actions.js

...
import { createAction } from 'redux-actions'

export const FETCH_CUSTOMERS = 'FETCH_CUSTOMERS';
export const fetchCustomers = createAction(FETCH_CUSTOMERS, (payload = {}) => payload, () => ({ retry: true }))

saga.js

import { all, call, fork, put, take } from 'redux-saga/effects'

import * as actions from './actions'
import * as api from '../../services/api'

 function* workfetchCustomers() {
  try {
    const data = yield call(api.fetchCustomers) // network api call
    yield put(actions.fetchCustomersSuccess(data))
  } catch (err) {
    yield put(actions.fetchCustomersFailure(err))
  }
}

function* watchfetchCustomers() {
  while (true) {
    yield take(actions.FETCH_CUSTOMERS)
    yield call(workfetchCustomers)
  }
}

export default function* rootSaga() {
  yield all([fork(watchfetchCustomers), fork(watchFetchProfile)])
}

middleware

  const networkMiddleware = createNetworkMiddleware({
    regexActionType: /^FETCH/,
    actionTypes: ['FETCH_CUSTOMERS'],
    queueReleaseThrottle: 1000,
  })

Your Environment

software version
react-native-offline ^5.8.0
react-native 0.64.2
redux-saga 1.1.3
node 16.4.1
npm or yarn 1.22.10
stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale commented

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

same issue, can we reopen this please?

Did you ever solve this?

I am having the same issue, using redux-saga v1.1.1

my action is dispatched from the actionQueue, and the reducer sets saving: true like it should. But the saga itself is never called.

edit: If anyone is having this issue, double check that you're following the correct order when doing applyMiddleware(networkMiddleware, sagaMiddleware) as mentioned in the Usage section 🤦🏻‍♂️