Giter Club home page Giter Club logo

Comments (8)

yelouafi avatar yelouafi commented on May 28, 2024

This is a weird side effect of using promises. I'm currently thinking of a consistent solution to this and other related issues (#50 && #34). Until it's fixed you can try this workaround used in the real world example

https://github.com/yelouafi/redux-saga/blob/master/examples/real-world/index.js#L15-L23

const store = configureStore()

requestAnimationFrame(() =>
  render(
    <Root
      store={store}
      history={history}
      routes={routes} />,
    document.getElementById('root')
  )
)

from redux-saga.

lvgunst avatar lvgunst commented on May 28, 2024

I had the same problem.

function *watchProfilesPage() {
  while (true) {
    console.log('listening for LOAD_PROFILES_PAGE actions');
    const { payload } = yield take(actions.LOAD_PROFILES_PAGE);
    console.log('LOAD_PROFILES_PAGE triggered');
  }
}

function *watchPaymentsPage() {
  while (true) {
    console.log('listening for LOAD_PAYMENTS_PAGE actions');
    const { payload } = yield take(actions.LOAD_PAYMENTS_PAGE);
    console.log('LOAD_PAYMENTS_PAGE triggered');
  }
}

export default function *root(getState) {
  yield fork(watchProfilesPage);
  yield fork(watchPaymentsPage);
}

In both my ProfilesContainer and PaymentsContainer I have componentWillMount where these actions are triggered:

// ProfilesContainer
componentWillMount() {
  console.log('trigger LOAD_PROFILES_PAGE');
  this.props.dispatch(loadProfilesPage(this.props.filters));
}
// PaymentsContainer
componentWillMount() {
  console.log('trigger LOAD_PAYMENTS_PAGE');
  this.props.dispatch(loadPaymentsPage(this.props.filters));
}

When my ProfilesContainer is active my console reads:

listening for LOAD_PROFILES_PAGE actions
trigger LOAD_PROFILES_PAGE
listening for LOAD_PAYMENTS_PAGE actions

The LOAD_PROFILES_PAGE action is successfully triggered and performed by the saga.

But when my PaymentsContainer is active my console reads:

listening for LOAD_PROFILES_PAGE actions
trigger LOAD_PAYMENTS_PAGE
listening for LOAD_PAYMENTS_PAGE actions

This time the seconds saga (LOAD_PAYMENTS_PAGE) is not listening on time to perform the LOAD_PAYMENTS_PAGE action.

I had to change the componentWillMount of my PaymentsContainer to wait a tick:

// PaymentsContainer
componentWillMount() {
  requestAnimationFrame(() => {
    console.log('trigger LOAD_PAYMENTS_PAGE');
    this.props.dispatch(loadPaymentsPage(this.props.filters));
  });
}

Console reads:

listening for LOAD_PROFILES_PAGE actions
listening for LOAD_PAYMENTS_PAGE actions
trigger LOAD_PAYMENTS_PAGE
LOAD_PAYMENTS_PAGE triggered

Edit. Thanks @yelouafi I will try to use the requestAnimationFrame on the render call for now.

from redux-saga.

yelouafi avatar yelouafi commented on May 28, 2024

@lvgunst Does the 2 containers load in the same time ?

from redux-saga.

lvgunst avatar lvgunst commented on May 28, 2024

No, these containers are route components. So only 1 container is active based on the active route. The thing is the second saga (watchPaymentsPage) is not listening when PaymentsContainer is triggering the action. Only the first registered saga (watchProfilesPage) is listening on time.

requestAnimationFrame solves this.

from redux-saga.

tgriesser avatar tgriesser commented on May 28, 2024

I had this issue as well, I ended up changing my root saga to yield an array and that took care of things. For the the example above, it'd be:

export default function *root(getState) {
  yield [
     fork(watchProfilesPage),
     fork(watchPaymentsPage)
  ]
}

from redux-saga.

yelouafi avatar yelouafi commented on May 28, 2024

Should be resolved by 0.6.0

from redux-saga.

yelouafi avatar yelouafi commented on May 28, 2024

did the new version solve the issue ?

from redux-saga.

lvgunst avatar lvgunst commented on May 28, 2024

Installed 0.6.0 and it seems to fix the problem. No need to use yield [] or requestAnimationFrame()

Thank you @yelouafi!

from redux-saga.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.