redux-dynamic-modules icon indicating copy to clipboard operation
redux-dynamic-modules copied to clipboard

Saga is not removed

Open hwzhang92 opened this issue 5 years ago • 3 comments

when use redux-dynamic-modules-saga, it dont remove saga when use DynamicModuleLoader or remove handle returned by store.addModules. When it add module again, the saga will also be two.

hwzhang92 avatar Mar 02 '20 17:03 hwzhang92

Are you using <StrictMode> any where in your React application?

abettadapur avatar Mar 24 '20 21:03 abettadapur

@abettadapur I've faced the same issue.

Saga with spawn does it.

function* rootSaga() {
  yield all([fork(someSaga1), spawn(someSaga2)])
}

also example from saga documentations

function* rootSaga () {
  const sagas = [
    saga1,
    saga2,
    saga3,
  ];

  yield all(sagas.map(saga =>
    spawn(function* () {
      while (true) {
        try {
          yield call(saga)
          break
        } catch (e) {
          console.log(e)
        }
      }
    }))
  );
}

Any ideas on how to solve it? I don't think there is any.

dmitry-prohorov avatar Apr 10 '20 11:04 dmitry-prohorov

spawn creates a saga at the root level, so it is not something we can cancel

If you use spawn, make sure to save a reference to the task so you can manually cancel it

abettadapur avatar Apr 10 '20 16:04 abettadapur