infinitered / reactotron

A desktop app for inspecting your React JS and React Native projects. macOS, Linux, and Windows.
https://docs.infinite.red/reactotron/
MIT License
14.74k stars 937 forks source link

Sagas trigger with takeLeading redux-sagas effect are not logged in reactotron. #1159

Open tatiesmars opened 4 years ago

tatiesmars commented 4 years ago

Sagas trigger with takeLeading redux-sagas effect are not logged in reactotron. Only takeLatest and takeEvery are working

siminino commented 4 years ago

Implementing takeLeading manually, using fork passing a saga with while(true) with a take action inside, is not working too. Example:

function* mySaga() {
  while(true) {
    yield take(SOME_ACTION);
    yield call(anotherSaga);
  }
}

export function* rootSaga() {
  yield all([
    fork(mySaga)
  ])
}

I don't know if this is really a Reactotron issue, or a reactotron-redux-saga issue.

siminino commented 4 years ago

This issue happens because takeLeading uses call to block waiting for the result of anotherSaga. The function call does not create a new Task to run anotherSaga, like fork does. Since takeLatest uses fork to run the new generator as non-blocking, a new Task is created and everything works fine.

The reactotron-redux-saga's sagaMonitor waits for the resolve state of Task's Promise to send data to Reactotron. https://github.com/infinitered/reactotron-redux-saga/blob/master/src/sagaMonitor.ts#L171-L177

I wrote a new takeLeading on my project that use fork to create a new Task, and join to block waiting for the result of that task. I don't know if this can cause some performance issues to the project, but now Reactotron is logging saga effects. Maybe I use just for debugging.

const takeLeading = (patternOrChannel, saga, ...args) => fork(function*() {
  while (true) {
    const action = yield take(patternOrChannel);
    const task = yield fork(saga, ...args.concat(action));
    yield join(task);
  }
})