Skip to content

Commit 6e30141

Browse files
committed
[Timers] Batch setImmediate handlers
Wraps the setImmediate handlers in a `batchedUpdates` call before they are synchronously executed at the end of the JS execution loop. Test Plan: Added two `setImmediate` calls to `componentDidMount` in UIExplorerApp. Each handler calls `setState`, and `componentWillUpdate` logs its state. With this diff, we can see the state updates are successfully batched. ```javascript componentDidMount() { setImmediate(() => { console.log('immediate 1'); this.setState({a: 1}); }); setImmediate(() => { console.log('immediate 2'); this.setState({a: 2}); }); }, componentWillUpdate(nextProps, nextState) { console.log('componentWillUpdate with next state.a =', nextState.a); }, ``` **Before:** "immediate 1" "componentWillUpdate with next state.a =", 1 "immediate 2" "componentWillUpdate with next state.a =", 2 **After:** "immediate 1" "immediate 2" "componentWillUpdate with next state.a =", 2
1 parent fc06dc8 commit 6e30141

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Libraries/Utilities/MessageQueue.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ class MessageQueue {
104104

105105
flushedQueue() {
106106
BridgeProfiling.profile('JSTimersExecution.callImmediates()');
107-
guard(() => JSTimersExecution.callImmediates());
107+
guard(() => {
108+
ReactUpdates.batchedUpdates(JSTimersExecution.callImmediates);
109+
});
108110
BridgeProfiling.profileEnd();
109111
let queue = this._queue;
110112
this._queue = [[],[],[]];

0 commit comments

Comments
 (0)