Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • Dec 02 08:25
    vimal1824 commented #2099
  • Dec 02 05:15
    subhadeepquantiantech commented #2099
  • Dec 02 04:46
    vimal1824 commented #2099
  • Nov 28 13:42
    Chanaka97n commented #2099
  • Nov 17 00:41
    github-actions[bot] commented #2341
  • Nov 17 00:40
    neurosnap review_requested #2341
  • Nov 17 00:40
    changeset-bot[bot] commented #2341
  • Nov 17 00:40
    neurosnap opened #2341
  • Nov 17 00:38

    neurosnap on format-all-js

    chore: run prettier on all files (compare)

  • Nov 17 00:34
    LordMoMA commented #2333
  • Nov 17 00:21
    neurosnap commented #2333
  • Nov 17 00:20
    neurosnap edited #2340
  • Nov 17 00:19
    neurosnap edited #2340
  • Nov 16 20:55
    neurosnap review_requested #2340
  • Nov 16 20:52
    github-actions[bot] commented #2340
  • Nov 16 20:51

    dependabot[bot] on npm_and_yarn


  • Nov 16 20:50
    dependabot[bot] commented #2339
  • Nov 16 20:50
    neurosnap closed #2339
  • Nov 16 20:50
    changeset-bot[bot] commented #2340
  • Nov 16 20:50
    neurosnap synchronize #2340
A Flores
I assume it gives you the possiblity to treat sagas as a message broker. I have a hard time arriving at a good use case, but like I said, creativity problems :)
ah, cool. thanks for the info
g. nicholas d'andrea
hey folks... does anyone happen to have a resource that describes the lifecycle of an action in the context of put/take? I'm having a hard time reasoning about put vs. putResolve, e.g., so more generally, I'm hoping to find a collection of sequence diagrams or something like that
Tim De Groote
Hey everyone, small question: Does redux-saga always run its effects synchronously? Or does it sometimes wait to execute its effects. The reason why I'm askin is because I have a case where two actions are called (ACTION1 and ACTION2). ACTION1 is dispatched first and ACTION2 shortly after. Now I need a saga to respond to ACTION1 before ACTION2 hits the reducer but from my console it looks like the saga is triggered when both ACTION1 and ACTION2 are already handled by the reducer.
Amir Off

Hello everyon,

I need help with this redux-saga/redux-saga#1762

Tormen Raßmann
@ameer157 your problem seems trivial but your description is lacking, please explain your issue more clearly
Amir Off

@trassmann I have a delete acition that calls a confirmation modal that can reject or accept the call. Let's say I clicked delete like five times then clicked no and sixth time clicked yes on the confirmation modal: the generator function calls the API for a delete request (six HTTP requests) - I checked in the network tab in chrome dev tools). It seems to that when clicking "No" the confirmation modal doesn't actually reject the call of the delete generator function.

Danke sehr! :)))

Matt Foxx
What's the difference between all and join when using an array of tasks (created from fork)?
ah nevermind, all is for effects and join is for tasks
but it looks like they do the same thing, essentially
A Flores
what is the difference between a task and an effect? I found the def of an effect: https://redux-saga.js.org/docs/basics/DeclarativeEffects.html essentially a json obj that will be run by the middleware.
Are you calling the generator functions tasks?
Ah nm, that is what it is
Rishi Kumar Chawda
Hi @all, I'm having trouble deciding how to handle global errors on my sagas and I was unable to find an elegant solution to it. Currently all my sagas have a huge try block which sends errors to sentry in its catch block if there's any error. Can someone please suggest me any better solution for this? I even followed up a few issues on the GitHub repo and stackoverflow but unfortunately I couldn't find something I can say can be considered as best practice. So I wanted to know how everyone else handles this. Any help, advice or suggestion is appreciated! Thanks in advance and I hope everyone is having a nice day!
A Flores
This doesn't surprise me, the nature of saga calls makes me think more of error catching on an individual basis. If you are hitting an api, then you'll have to deal with 400 etc. That type of thing should probably be dealt with on a case by case basis. If you are looking for a global catch-all, I found this in github: redux-saga/redux-saga#1672
It might correspond to your needs @rishichawda
Rishi Kumar Chawda
@unflores I am aware of that issue and solution given there, but as you can see that makes the root saga terminate. Which I don't want. I want to handle the errors and restart / rollback etc if anything like that happens.
Rishi Kumar Chawda
Also, I'm using apisauce for calls to my api server so everything in the requests part is handled very well right now. What I wanted to do is make sure I handle possible scenarios that might happen in the production which cannot be reproduced so well manually. Like what if there's an inconsistent state or what if the data is corrupted or what if something happens on put or call. I need to handle those errors too. I'm not concerned about anything breaking in the UI since I'm having error boundaries for them but I need to make sure everything works fine with sagas too. Right now I pretty much have one try catch block in every saga which kind of feels redundant and doesn't look pretty to me. So I was looking for an elegant way to do that.
How do you handle errors in your saga btw? @unflores
A Flores
@rishichawda we catch them in individual sagas. For me that makes the most sense, anything that gets up to the mainSaga error handler is more of a "catastrophic" error, I don't want to handle it b/c I wasn't expecting it. I just want to log it somewhere so I can deal with it later. I treat it as equivilant to a 500 from an api.
Evan Meeks
@rishichawda apisauce NICE!
@rishichawda I've been looking for something solid like this
Rishi Kumar Chawda
@evanmeeks glad you found it useful. it is my go to solution for setting up things quick!
Hello guys how can I get cookie with in the reducer
Chris LeBlanc
Hello, I'm having trouble understanding how/when to use fork/all... when registering "rootSagas"... I'm using redux-saga-requests and my sagas are broken into redux "duck" like modules, any duck may fire redux saga requests.
What I'm currently facing though I think is unrelated... for some reason my takeLatest from one module is not responding to another's action fired I think
in my rootSaga I have yield createRequestInstance(); yield watchRequests(); all([fork(duck1), fork(duck2)]);
Chris LeBlanc
I guess to make a digestible question, what's the relationship between something that is forked and takeLatest?
Tormen Raßmann
takeLatest takes the action from the standard channel and forks a new task, if the same action is fired again while an old task is still running it gets cancelled AFAIK
and a forked task is just a forked task
you need to yield the all effect as well though
yield all([fork(duck1), fork(duck2)]);
Mladen Petrović
Hey all, i am getting error call: argument of type {context, fn} has undefined or null while trying to compose sagas.
I have no idea whats wrong
Monteiro Steed

Hello @everyone

We’re looking for React/React Native engineers to work as part of our community. We have multiple projects and missions, where you choose on what you want to work. There is no hiring process, so keep your resumate... it’s an open organisation, here only our work matter :)

StudioLabs is a 100% remote international company, originally founded in Paris, France. We help companies develop their applications by providing them skills of developers and designers from around the world. We believe in living a life of freedom, where freelancers can choose their missions.

Join our community here:http://bit.ly/2w2BHYO

@rishichawda hey I hope this reply isn't too late, but you can have sagas call each other in a chain, so you can consolidate all your generic error handling in one place. For example, instead of takeEvery(GET_RESOURCE_ACTION, getResources) and have getResources call the api directly, you can have getResources handle composing parameters / handling api response. In the middle, getResources might yield call callAndHandleApiErrors which deals with figuring out which api-specific things you need like headers, endpoints, etc... and dealing with api-level response errors. And within callAndHandleApiErrors you might have yet another saga that does the actual fetch call itself, and handles network-level issues. For example, if you want to auto-retry an api call X amount of times, you might pass that as a parameter down to the fetch* saga which can handle retrying your api call, and if it fails X times then it can dispatch an error and return something to the callAndHandleApiErrors saga so that it knows that it can proceed (e.g. just return null or something).
Using redux-saga-test-plan, any idea why my generator that returns a Promise would cause test to time out? Getting error: "Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout."
Can someone explain how the saga middleware works under the hood? Like I understand how middlewares work and I understand what take/takeEvery ect does, but I don't understand how the saga middleware does its job of getting the actions to the right sagas. Or maybe point me to a resource that explains it?
Ahmad R
hi guys , how do i pass an argument from the action creator to my saga ?
In the documentation on task cancellation (https://redux-saga.js.org/docs/advanced/TaskCancellation.html), it shows how to test that a task was cancelled, but it seems to me to be waaay more important to test that the code in the task that actually does the real cancellation (if yield(cancelled) {abortController.abort()} for example) runs. But I haven't been able to figure out how you create a generator as a task and cancel it so that I can test this. I think I understand how to spy on the constructor for AbortController so I can look at what happened--I just have no clue how to make it happen in a test scenario. The code would normally get cancelled by takeLatest.
@harvester-klirk , if you're asking what I think you're asking, the action itself will be the argument, and you'll look at its properties to determine what you should do. In addition, you can get access to the state using select() to fill in any gaps.
For anyone else wanting to test the finally logic in a canceled saga, I found the answer here https://stackoverflow.com/questions/46166401/unit-testing-redux-saga-task-cancellation https://github.com/redux-saga/redux-saga/issues/266#issuecomment-216087030. Hope this helps someone
Matti Järvinen
Kinda related to @AmyBlankenship ´s question. I'm testing a full saga with runSaga. How would I add another action in there so I can test that it cancels the previous one?
for v1.o, catch not work? const rootTask = sagaMiddleware.run(rootSaga)
anybody know the issue
Aleksander Vognild Burkow
@gilbsgilbs i'm having a look at your dtslint branch
I'm not having any trouble running the tests, and think i might be getting other erors than you described
i get straight-up normal errors:
Error: /Users/aleksandervognildburkow/Projects/redux-saga/packages/core/types/ts3.5/channels.test.ts:24:1
ERROR: 24:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 32:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 45:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 47:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 51:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 56:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 58:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 82:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 90:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 99:1    expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 112:1   expect  TypeScript@next: Expected an error on this line, but found none.
ERROR: 116:1   expect  TypeScript@next: Expected an error on this line, but found none.

In order for the execution exception of an effect to not affect the whole, I created a wrapper function. For example, the following adds safety to each effect, which solves the problem.

But if my effect is very large, it is very time consuming and not elegant to manually increase the safety. I want to know if there is any way, such as a loop function to automatically add safety to each effect, which makes the code more beautiful.

wrapper function

import { call } from 'redux-saga/effects';

export function safe(sagaFn) {
  return function* (action) {
    try {
      return yield call(sagaFn, action);
    } catch (e) {
      console.error('[react-demo | Saga Unhandled Exception] This error should be fixed or do some pre check in saga effects function.');


function* mySaga() {
    yield takeEvery('USER_FETCH', safe(fetchUserEffects));
    yield takeEvery('TEST_SAGA', safe(testSagaEffects));
    yield takeEvery('TEST_SAGA', safe(testSagaEffects2));