question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Startup race condition - sagas injected after dispatched actions don't fire

See original GitHub issue

Description

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:open
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
alon-scommented, Jun 1, 2020

Thinking about it even further, the useInjectSaga has a different behavior then the HOC. While useInjectSaga uses the useEffect hook, which is similar to componentDidMount, the injectSaga HOC uses the constructor. This is what causes the unexpected behavior from children nodes that are using useEffect or componentDidMount.

0reactions
tmreaycommented, Apr 23, 2020

The more I think about it, a better solution is probably to just use the injectSaga HOC, instead of the hook.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found