{"action":"created","issue":{"url":"https://api.github.com/repos/react-boilerplate/react-boilerplate/issues/1434","repository_url":"https://api.github.com/repos/react-boilerplate/react-boilerplate","labels_url":"https://api.github.com/repos/react-boilerplate/react-boilerplate/issues/1434/labels{/name}","comments_url":"https://api.github.com/repos/react-boilerplate/react-boilerplate/issues/1434/comments","events_url":"https://api.github.com/repos/react-boilerplate/react-boilerplate/issues/1434/events","html_url":"https://github.com/react-boilerplate/react-boilerplate/issues/1434","id":199802768,"number":1434,"title":"Sagas are injected twice!?","user":{"login":"williamgranli","id":6433394,"avatar_url":"https://avatars2.githubusercontent.com/u/6433394?v=3","gravatar_id":"","url":"https://api.github.com/users/williamgranli","html_url":"https://github.com/williamgranli","followers_url":"https://api.github.com/users/williamgranli/followers","following_url":"https://api.github.com/users/williamgranli/following{/other_user}","gists_url":"https://api.github.com/users/williamgranli/gists{/gist_id}","starred_url":"https://api.github.com/users/williamgranli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/williamgranli/subscriptions","organizations_url":"https://api.github.com/users/williamgranli/orgs","repos_url":"https://api.github.com/users/williamgranli/repos","events_url":"https://api.github.com/users/williamgranli/events{/privacy}","received_events_url":"https://api.github.com/users/williamgranli/received_events","type":"User","site_admin":false},"labels":[{"id":306827362,"url":"https://api.github.com/repos/react-boilerplate/react-boilerplate/labels/unconfirmed-bug","name":"unconfirmed-bug","color":"f7c6c7","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":39,"created_at":"2017-01-10T11:58:05Z","updated_at":"2017-06-27T03:57:01Z","closed_at":"2017-01-18T08:31:14Z","body":"For some reason, the sagas are injected twice in a new project I started. I did not have this problem in my previous project, even though the code is the same from what I can tell. \r\n\r\nroutes.js\r\n\r\n```\r\nimport { getAsyncInjectors } from 'utils/asyncInjectors';\r\n\r\nconst errorLoading = (err) => {\r\n  console.error('Dynamic page loading failed', err); // eslint-disable-line no-console\r\n};\r\n\r\nconst loadModule = (cb) => (componentModule) => {\r\n  cb(null, componentModule.default);\r\n};\r\n\r\nexport default function createRoutes(store) {\r\n  // Create reusable async injectors using getAsyncInjectors factory\r\n  const { injectReducer, injectSagas } = getAsyncInjectors(store); // eslint-disable-line no-unused-vars\r\n  console.log(\"in route\");\r\n  return [\r\n    {\r\n      path: '/',\r\n      name: 'consolePage',\r\n      getComponent(nextState, cb) {\r\n        const importModules = Promise.all([\r\n          System.import('containers/ConsolePage/reducer'),\r\n          System.import('containers/ConsolePage/sagas'),\r\n          System.import('containers/ConsolePage'),\r\n        ]);\r\n\r\n        const renderRoute = loadModule(cb);\r\n\r\n        importModules.then(([reducer, sagas, component]) => {\r\n          injectReducer('consolePage', reducer.default);\r\n          injectSagas(sagas.default);\r\n          renderRoute(component);\r\n        });\r\n\r\n        importModules.catch(errorLoading);\r\n      },\r\n    }, {\r\n      path: '*',\r\n      name: 'notfound',\r\n      getComponent(nextState, cb) {\r\n        System.import('containers/NotFoundPage')\r\n          .then(loadModule(cb))\r\n          .catch(errorLoading);\r\n      },\r\n    },\r\n  ];\r\n}\r\n```\r\n\r\nConsolePage/sagas.js\r\n\r\n```\r\nexport function* root() {\r\n  console.log(\"starting saga\")\r\n  const watcher1 = yield fork(a);\r\n  const watcher2 = yield fork(b);\r\n  const watcher3 = yield fork(c);\r\n  const watcher4 = yield fork(d);\r\n  const watcher5 = yield fork(e);\r\n\r\n  yield take(LOCATION_CHANGE);\r\n  yield cancel(watcher1);\r\n  yield cancel(watcher2);\r\n  yield cancel(watcher3);\r\n  yield cancel(watcher4);\r\n  yield cancel(watcher5);\r\n}\r\n\r\nexport default [\r\n  root,\r\n];\r\n```\r\nWhere a, b, c, d and e are generator function as below:\r\n```\r\nexport function* a() {\r\n  while (true) { // eslint-disable-line no-constant-condition\r\n    const action = yield take(X);\r\n    const id = action.payload.id;\r\n    const url = path + ':10020/' + id + '/logs';\r\n    const response = yield call(y, url);\r\n    if (response) {\r\n      const logs = response.data;\r\n      yield put({ type: z, payload: { asd } });\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nWhen printing the root function in the saga, the print happens twice. And when printing in the main function in routes.js, it happens once. The reducer receives two actions, one is INIT and the other is LOCATION_CHANGE from react-redux-router (from null to index since it's the first loading of the page). \r\n\r\nAt first I thought the problem was related to not canceling sagas, but I am doing that as you can see in sagas.js. I'm running an older version of the boilerplate on my other project, so it might be that canceling sagas like this doesn't work anymore, any info on that?\r\n\r\nAny help is appreciated, thanks!"},"comment":{"url":"https://api.github.com/repos/react-boilerplate/react-boilerplate/issues/comments/311246194","html_url":"https://github.com/react-boilerplate/react-boilerplate/issues/1434#issuecomment-311246194","issue_url":"https://api.github.com/repos/react-boilerplate/react-boilerplate/issues/1434","id":311246194,"user":{"login":"bjackson","id":47246,"avatar_url":"https://avatars3.githubusercontent.com/u/47246?v=3","gravatar_id":"","url":"https://api.github.com/users/bjackson","html_url":"https://github.com/bjackson","followers_url":"https://api.github.com/users/bjackson/followers","following_url":"https://api.github.com/users/bjackson/following{/other_user}","gists_url":"https://api.github.com/users/bjackson/gists{/gist_id}","starred_url":"https://api.github.com/users/bjackson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjackson/subscriptions","organizations_url":"https://api.github.com/users/bjackson/orgs","repos_url":"https://api.github.com/users/bjackson/repos","events_url":"https://api.github.com/users/bjackson/events{/privacy}","received_events_url":"https://api.github.com/users/bjackson/received_events","type":"User","site_admin":false},"created_at":"2017-06-27T03:57:01Z","updated_at":"2017-06-27T03:57:01Z","body":"@Dattaya is that in addition to Gyvastis's changes?"}}
{"actor":{"display_login":"bjackson"}}