Comments (8)
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.
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.
@lvgunst Does the 2 containers load in the same time ?
from redux-saga.
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.
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.
Should be resolved by 0.6.0
from redux-saga.
did the new version solve the issue ?
from redux-saga.
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)
- yield and takeLatest not working with jest HOT 8
- Waiting for an action with takeMaybe / take after END is dispatched for SSR HOT 7
- Is it possible to selectively cancel tasks in an actionChannel? Ie cancel the 3rd task out of 5 running ones. HOT 5
- Is it possible for a saga to "trace" the effect "chain"? HOT 4
- Delay inside of while loop may never fire with React Native 0.71.6 HOT 2
- UI freezes when chrome devtools is open HOT 4
- Redux 4.0 - Unable to access updated data using useSelector HOT 2
- could we add leading/trailing edge options for debounce? HOT 3
- Workflow has flaw
- Why not use the await and async instead of the generator and yield? HOT 1
- TS2345 error while putting thunk actions
- React native Redux Saga with Redux Tollkit
- Module '"redux-saga/effects"' has no exported member 'call'. HOT 4
- Is there a standard way to break while true loops with call effect when END is dispatched? HOT 1
- Can put type improvements be released downstream? HOT 2
- Sending very large files, tasks in parallel are using a lot of memory
- How to use package that use redux-saga as dependency when its in webpack externals? HOT 7
- Help me connect redux-saga with Nextjs 13.5 using app router HOT 2
- Update peer dependencies to include `redux@5` (currently beta) HOT 14
- feature request: interface for integration with other frameworks (like Vue) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-saga.