Skip to content
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

Effects do not catch the actions when fork inside all after 1.0.0-beta.3 #1733

Closed
purepennons opened this issue Jan 18, 2019 · 12 comments
Closed

Comments

@purepennons
Copy link

purepennons commented Jan 18, 2019

Steps to reproduce

Description of the bug/issue

See the example. I run a saga by fork inside all. The effects (only tried takeEvery and takeLatest) do not catch the action and run the sagas after 1.0.0-beta.3 version.

Steps to reproduce the bug/issue

  1. click inc/dec button to increment/decrement the state.

Example

All examples are same except the redux-saga version.

Actual results

  • Buttons of 1.0.0-rc.0 and 1.0.0-beta.3 have no responses.
  • 1.0.0-beta.2 and 0.16.2 take all actions and increment/decrement the state correctly.

The Expected results

All version should take all actions and increment/decrement the state correctly.

Environment information

  • redux-sage 1.0.0-rc.0, 1.0.0-beta.3, 1.0.0-beta.2 , 1.0.0-beta.1, 0.16.2
@feichao93
Copy link
Member

After changing...

export function* process() {
  yield all([
    fork(takeEvery, Types.DO_INC, increment),
    fork(takeEvery, Types.DO_DEC, decrement)
  ]);
}

to

export function* process() {
  yield all([
    takeEvery(Types.DO_INC, increment),
    takeEvery(Types.DO_DEC, decrement)
  ]);
}

... then everything works as expected.

Because takeEvery is already a wrapper of fork, fork(takeEvery, ...) is unneccessary. Just use takeEvery(...) 😸

@purepennons
Copy link
Author

purepennons commented Jan 18, 2019

@shinima
I know, but that is a breaking change.

@Andarist
Copy link
Member

Yes, we know - that's why it is listed in https://github.com/redux-saga/redux-saga/releases/tag/v1.0.0-beta.3 "Fixed" section.

@GuillaumeCisco
Copy link

GuillaumeCisco commented Feb 15, 2019

I have the exact same issue from version >= 1.0.0.
I use this pattern for loading my sagas:

import {fork} from 'redux-saga/effects';
import my_saga from './my_saga';

export default function* root() {
    yield fork(my_saga);
}

The my_saga.js file looks like:

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

function* myGenerator(request) {
    // do stuff, yield stuff
}

export default function* () {
    yield all([
        takeLatest(MY_ACTION_TYPE, myGenerator),
    ]);
}

The myGenerator function is never called :/
AND it looks like the yield all is never reached too.

@Andarist
Copy link
Member

could you prepare a codesandbox.io showcasing the problem?

@GuillaumeCisco
Copy link

GuillaumeCisco commented Feb 15, 2019

@Andarist Simply using the beginner tutorial.
Following: https://redux-saga.js.org/docs/introduction/BeginnerTutorial.html
github repo : https://github.com/redux-saga/redux-saga-beginner-tutorial
Clone it, go inside the sagas branch, modify the package.json for having "redux-saga": "1.0.1".
Then, yarn install, yarn run.

Go to the webpage, it does not work on my computer.

yarn : 1.13.0
node : v11.10.0

If someone can confirm it.

codesandbox is here: https://codesandbox.io/s/nwj4jrm1n0
The one with old version : https://codesandbox.io/s/qkr84w2w is working
Thank you,

@feichao93
Copy link
Member

@GuillaumeCisco You should use yield all([...]) instead of yield [...] in the root saga, and this is why the code is not working in 1.0.1.

Actually, if you view the logs in 0.16.x, there is a deprecation warning which tells you to update the code.

@GuillaumeCisco
Copy link

@shinima I took the code from the official tutorial as you can see.
I succeeded to make the tutorial work by adding the yield all([...]) and replacing the yield call(delay, 1000) by yield delay(1000) with an import { all, put, takeEvery, delay } from "redux-saga/effects";

The tutorial is not up to date.

Unfortunately, it changed nothing in my own project, effects are not called...

@GuillaumeCisco
Copy link

Ok I just found out my issue.
I use redux-sagas-injector https://github.com/GuillaumeCisco/redux-sagas-injector.
I'm the maintainer of this lib.
Issue is redux-sagas-injector use a old version of redux-saga and is in charge to create the sagaMiddleware: const sagaMiddleware = createSagaMiddleware();

When mixing old and new versions of redux-sagas with dependencies, effects are not called.
I'm thinking how to make the code compatible for both versions without breaking changes...

@Andarist
Copy link
Member

From what I see the @GuillaumeCisco has handled the problem on his side (inside redux-saga-injector) and originally reported issue actually works as expected - therefore Im closing this issue as resolved, feel free to open new issues though if needed

@GuillaumeCisco
Copy link

Thanks @Andarist.
However, I think the beginner tutorial should be updated ;)

@Andarist
Copy link
Member

I think it's already updated - if you can please check it in the git repository, not on the website. I'm planning to redeploy docs website after doing a patch release which I'm sort of preparing right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants