-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wait for an action with TAKE after END is dispatched for SSR #1117
Comments
Actually I have just found a solution: function* articlesSaga() {
yield put.resolve(fetchArticles()); // axios middleware actions return promises, so this blocks saga until it is resolved
} I will leave this issue opened, as I am still wondering whether it is still possible to block on while(true) {
const action = yield take.maybe('SOME_ACTION');
if (action.type !== END.type) {
break;
}
} but this just leads to an infinitive loop, so I guess you cannot receive any action other than |
You might want to try restructure your code (cannot give any real advice here without having deeper knowledge about your codebase) in a way that You might also consider using channels for inter saga communication. I think this would allow you to bypass the stdChannel restriction. |
Ok, thanks for confirmation. In my case Thanks for the tip with |
@klis87 aint sure how ur code is structured, but using 2 async sources of actions - axios middleware and sagas - might cause u some headaches like that. They both ofc work just fine together, but sometimes integration in trickier cases (like SSR) might be harder. |
@Andarist OK, I see. My main problem is, that I would like to use axios interceptors, so I will need to create axios instance for each request so each axios instance would have acess to a separate store. The problem is, how my sagas could get access to this instance? I thought about passing it as |
You can leverage the context feature (which is not documented unfortunately atm). You can use |
ohhh great! that's exactly what I needed! Maybe I will even write a library like |
@klis87, awesome! |
I have a problem with fetching all of my dependencies during SSR with sagas - I use real world example and
END
action.The following works:
Above, saga is not blocked on
take
and it will do its job beforerunSaga().done.then
is triggered.However, I want to switch to https://github.com/svrcekmichal/redux-axios-middleware for my api calls, so I need something like this:
The problem is, that
take.maybe
receivesEND
signal, even if i yield it multiple times. Is there any way to do some cleanup of saga afterEND
is dispatched, to force it to wait for a final action? Because right now,articlesSaga
is terminated beforeFETCH_ARTICLES_SUCCESS
goes to my reducer so I cannot set articles as my initial state.The text was updated successfully, but these errors were encountered: