rgommezz/react-native-offline

Dismiss doesn't work with fetchOfflineMode when online

Gueoff opened this issue · 3 comments

Hello!
I have to dismiss all the queue when I logout and reput these actions when I login (actions stored somewhere else and depending of the connected user).
To do it, I use the dismiss meta attribute like that:

  yield put({
    type: 'FETCH_UPDATE_USER_REQUEST',
    payload: {user},
    meta: {
      dismiss: ['LOGOUT'],
      retry: true,
    },
  });

This code works when I let rn-offline put this action in the store. The actionQueue = [].

Then, I want to put all stored actions in the network reducer, so I'm using fetchOfflineMode like that:

const {fetchOfflineMode} = offlineActionCreators;
yield all(
  queuedActions.map(queuedAction => put(fetchOfflineMode(queuedAction))),
);

I works fine, all my actions are in the network store.

I can logout/login as much that I want, it works.
BUT only when I'm offline.

Current Behavior

  • Turn connection Off
  • Add actions with fetchOfflineMode (action with dismiss: 'LOGOUT')
  • Turn connection On
  • dispatch LOGOUT

network reducer / actionQueue contains the actions.

Expected Behavior

  • Turn connection Off
  • Add actions with fetchOfflineMode (action with dismiss: 'LOGOUT')
  • Turn connection On
  • dispatch LOGOUT

network reducer / actionQueue must be empty

Your Environment

software version
react-native-offline 5.7.0
react-native 0.61.4
node 12.18.0
yarn 1.9.4

Note

Maybe there is a better way to clear the reducer? I want to manage multi account where each account get his own queue

Hey @Gueoff,

That's how the library is designed to work, only dismissing when you are offline. In theory, the moment you switch the connection back on, the queue should flush. Maybe it's a race condition, not sure.

You can tweak this line to remove the offline condition and experiment yourself. For that, feel free to use patch-package to easily modify it inside node_modules

If all looks good, I am happy to accept a PR if needed.

Cheers.

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.