microsoft / redux-dynamic-modules

Modularize Redux by dynamically loading reducers and middlewares.
https://redux-dynamic-modules.js.org
MIT License
1.07k stars 116 forks source link

Saga is not removed #137

Open hwzhang92 opened 4 years ago

hwzhang92 commented 4 years ago

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.

abettadapur commented 4 years ago

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

dmitry-prohorov commented 4 years ago

@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.

abettadapur commented 4 years ago

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