{"id":26176,"library":"redux-sagas-injector","title":"redux-sagas-injector","description":"A library for dynamically injecting Redux sagas at runtime, enabling code splitting and lazy loading of sagas. Version 1.1.5 supports redux-saga 1.x and provides helpers for HMR and SSR. Unlike manual store manipulation, it uses a central key-based tracking mechanism and works alongside redux-reducers-injector. It has a small API surface (createInjectSagasStore, injectSaga, injectSagaBulk, reloadSaga) and is popular in universal/isomorphic React apps. Release cadence is irregular; current version fixes security issues in dependencies. Key differentiators: built-in HMR support, context store usage, and compatibility with react-universal-component.","status":"active","version":"1.1.5","language":"javascript","source_language":"en","source_url":"https://github.com/GuillaumeCisco/redux-sagas-injector","tags":["javascript","redux","react","redux-sagas"],"install":[{"cmd":"npm install redux-sagas-injector","lang":"bash","label":"npm"},{"cmd":"yarn add redux-sagas-injector","lang":"bash","label":"yarn"},{"cmd":"pnpm add redux-sagas-injector","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; requires a Redux store to inject sagas into.","package":"redux","optional":false},{"reason":"Peer dependency (version 1.x); injects sagas managed by redux-saga middleware.","package":"redux-saga","optional":false},{"reason":"Optional companion for injecting reducers alongside sagas; mentioned in docs as a pairing tool.","package":"redux-reducers-injector","optional":true}],"imports":[{"note":"Library supports both ESM and CJS. Use named import for ESM; require will give an object with named exports.","wrong":"const createInjectSagasStore = require('redux-sagas-injector')","symbol":"createInjectSagasStore","correct":"import { createInjectSagasStore } from 'redux-sagas-injector'"},{"note":"Default import is not available; must use named import.","wrong":"import injectSaga from 'redux-sagas-injector'","symbol":"injectSaga","correct":"import { injectSaga } from 'redux-sagas-injector'"},{"note":"sagaMiddleware is a pre-initialized middleware instance; no need to create your own with createSagaMiddleware.","wrong":"import sagaMiddleware from 'redux-sagas-injector/lib/sagaMiddleware'","symbol":"sagaMiddleware","correct":"import { sagaMiddleware } from 'redux-sagas-injector'"},{"note":"Used for HMR; accepts the same key as injectSaga and the new saga module.","wrong":null,"symbol":"reloadSaga","correct":"import { reloadSaga } from 'redux-sagas-injector'"},{"note":"Accepts an array of objects with 'key' and 'saga' properties.","wrong":null,"symbol":"injectSagaBulk","correct":"import { injectSagaBulk } from 'redux-sagas-injector'"}],"quickstart":{"code":"import { createStore, applyMiddleware, compose } from 'redux';\nimport { createInjectSagasStore, sagaMiddleware, reloadSaga, injectSaga } from 'redux-sagas-injector';\n\n// Define a sample saga\nfunction* mySaga() {\n  console.log('Saga started');\n}\n\n// Create store with inject capability (replaces createStore)\nconst rootReducer = (state = {}) => state;\nconst store = createInjectSagasStore(\n  { rootSaga: mySaga },  // initial sagas as object { key: sagaFunc }\n  rootReducer,\n  undefined,\n  compose(applyMiddleware(sagaMiddleware))\n);\n\n// Inject additional saga later\ninjectSaga('anotherSaga', function* () {\n  console.log('Injected saga runs');\n});\n\n// HMR example (in module)\nif (module.hot) {\n  module.hot.accept('./sagas', () => {\n    const newSaga = require('./sagas').default;\n    reloadSaga('rootSaga', newSaga);\n  });\n}","lang":"typescript","description":"Demonstrates creating a store with injected sagas, injecting a saga later, and hot reloading. Uses TypeScript-style imports but works in JavaScript."},"warnings":[{"fix":"Upgrade redux-saga to 1.x and ensure all sagas are generator functions. Remove any legacy buffer or channel usage.","message":"Version 1.0.0 dropped support for redux-saga 0.x; saga must be a generator function or fork/race pattern. The old 0.2.x versions are incompatible with redux-saga 1.x.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Upgrade to v1.0.0 or later to avoid transform-runtime conflicts.","message":"In version 0.2.9, using transform-runtime for generators caused issues; the library reverted to 0.2.9 for generator compatibility. This is no longer relevant in v1.x.","severity":"deprecated","affected_versions":"<=0.2.9"},{"fix":"Use reloadSaga to replace an existing saga, or call injectSaga only once per key (e.g., in component lifecycle). If using React component, ensure injectSaga is called only on mount.","message":"injectSaga with a duplicate key silently does nothing. There is no error or warning. This can lead to sagas not being replaced if you expect it to work like injectReducer for reducers.","severity":"gotcha","affected_versions":"*"},{"fix":"Only use one store per application, or create your own sagaMiddleware using createSagaMiddleware from redux-saga if you need multiple stores.","message":"The sagaMiddleware exported by this library is a single instance. If you create multiple stores, they will share the same middleware instance, which may cause issues (e.g., sagas from one store influencing another).","severity":"gotcha","affected_versions":"*"},{"fix":"Evaluate migrating to Redux Toolkit's configureStore and dynamic middleware/reducer injection patterns.","message":"The package uses deprecated dependency 'redux-reducers-injector' which has similar API. Consider using Redux Toolkit's dynamic reducers approach instead, as this library is not actively maintained (last release 2020).","severity":"deprecated","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use createInjectSagasStore (not createStore) and ensure sagaMiddleware is in the applyMiddleware chain. Example:\nconst store = createInjectSagasStore({}, rootReducer, initialState, compose(applyMiddleware(sagaMiddleware)));","cause":"Saga was not properly injected or the sagaMiddleware was not applied to the store. This often happens when using createStore instead of createInjectSagasStore, or when sagaMiddleware is not included in enhancers.","error":"Error: Actions must be plain objects. Use custom middleware for async actions."},{"fix":"Do not call sagaMiddleware.run(). The library handles running sagas internally via injectSaga. If you need to run a root saga manually, use createInjectSagasStore with initial sagas object.","cause":"The sagaMiddleware imported from redux-sagas-injector is not a function; it's a pre-initialized middleware instance. Trying to call .run on it directly fails.","error":"TypeError: sagaMiddleware.run is not a function"},{"fix":"Import as:\nimport { sagaMiddleware } from 'redux-sagas-injector';","cause":"Trying to import from an internal path that does not exist in the library's published package. The sagaMiddleware is exported from the main entry point.","error":"Cannot find module 'redux-sagas-injector/lib/sagaMiddleware'"},{"fix":"Use named import:\nimport { injectSaga } from 'redux-sagas-injector';","cause":"Using default import instead of named import. The library does not have a default export.","error":"injectSaga is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}