Description
React version: 17.0.2
When using React.useReducer()
and a new action is pushed, but the reducer returns the current state, the operation is queued in a pending queue. But if the component isn't re-rendered for other reasons, it will never start work on that pending queue. This can potentially rack up a huge list of pending.next.next.next.next...
Steps To Reproduce
- https://codesandbox.io/s/unruffled-moore-wp5wq?file=/src/App.js
- click increment a few times
- place a breakpoint in react-dom.development.js line 16072, click increment, that should hit the break point, then expand queue.pending.next.next.next and see they are unique actions. ( )
Link to code example: https://codesandbox.io/s/unruffled-moore-wp5wq?file=/src/App.js
The current behavior
There is no change in behavior, but it is potentially racking up an enormous list of pending tasks, costing memory.
The expected behavior
Flat memory usage. Reducer doesn't run twice on the same action.
This is very much related to #15198 because later the reducer might run, and basically reduce the same actions again. Which is unexpected. And if using side-effects, doesn't produce the expected results.