Automatic Batching: Inconsistent Render Counts Across Event and Timer Callbacks
0 reputation · 15 May 2021, 16:32 UTC
Goal
Determine the precise conditions under which React 18's automatic batching groups multiple state updates into a single render.
Constraints and uncertainty
Automatic batching is documented to apply to event handlers and promise callbacks but excludes timer-based callbacks outside React's control. In Concurrent Mode, the scheduler may further delay batched updates until the next microtask. The behavior also differs between React DOM and React Native, and the opt-out API unstable_batchedUpdates is deprecated in React 19.
Questions
- Which callback types reliably trigger automatic batching in React 18 Concurrent Mode?
- How does the scheduler's microtask timing affect the observable render count for batched updates?
- What is the recommended pattern to achieve consistent batching across React DOM and React Native without relying on deprecated APIs?