Startup race condition - sagas injected after dispatched actions don't fire
See original GitHub issueDescription
Suppose a child component of a parent container dispatches an action from the parent container (with useEffect
or useLayoutEffect
), the action is dispatched before the saga watchers (and even the parent reducer) have started and is thus missed.
If this isn’t a bug, what are the best strategies to accomplish something like this. Adding a delay in the use hook seems wrong.
Steps to reproduce
See example
Expected behavior
I would expect the parent’s reducers/sagas to be injected by the time the child dispatches the action. In this case, the state should have the new username.
Screenshots If applicable, add screenshots to help explain your problem.
Versions
- React-Boilerplate: dev (master too)
- Node/NPM: 6.13.6 Browser: brave/chrome
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
How to dispatch a Redux action with a timeout? - Stack Overflow
When the first timeout finishes, it will dispatch HIDE_NOTIFICATION , erroneously hiding the second notification sooner than after the timeout.
Read more >Racing Effects | Redux-Saga
The race Effect offers a way of triggering a race between multiple Effects. The following sample shows a task that triggers a remote...
Read more >https://www.legis.iowa.gov/docs/iac/chapter/02-04-...
“Starter” means a horse that becomes an actual contestant in a race by virtue of the starting gate opening in front of it...
Read more >COVID-19: Fear, quackery, false representations and the law
Such conditions, even when subclinical, tend to be a product of personal and ... The series of Resident Evil horror films starting in...
Read more >C++ Core Guidelines - GitHub Pages
You cannot have a race condition on immutable data. References: See the rules for calling functions. Note. The rule is “avoid”, not “don't...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thinking about it even further, the
useInjectSaga
has a different behavior then the HOC. WhileuseInjectSaga
uses theuseEffect
hook, which is similar tocomponentDidMount
, theinjectSaga
HOC uses the constructor. This is what causes the unexpected behavior from children nodes that are usinguseEffect
orcomponentDidMount
.The more I think about it, a better solution is probably to just use the
injectSaga
HOC, instead of the hook.