Always trigger an update when a callback is enqueued.
enqueueCallbackInternal forgot to schedule an update. We could rely on the implicit contract of enqueueElement to do it. However, if we're currently outside a transaction, it'll flush synchronously. Before we enqueue the callback. We could also enqueueCallback before we enqueueElement, but that causes a fragile relationship between them. E.g. enqueueElement should not need to schedule an update if it is the same element.
Sebastian Markbage committed
Feb 2, 2015 at 20:42 UTC
2702281a130e8118b70fcd37f71d22b49f5fd837
2 files changed
+15
src/core/ReactUpdateQueue.js
+1
@@ -111,6 +111,7 @@ var ReactUpdateQueue = {
111
} else {
112
internalInstance._pendingCallbacks = [callback];
113
}
114
+ enqueueUpdate(internalInstance);
115
},
116
117
/**
src/core/__tests__/ReactComponent-test.js
+14
@@ -15,10 +15,12 @@ var React;
15
var ReactInstanceMap;
16
var ReactTestUtils;
17
18
+var mocks;
19
var reactComponentExpect;
20
21
describe('ReactComponent', function() {
22
beforeEach(function() {
23
+ mocks = require('mocks');
24
React = require('React');
25
ReactInstanceMap = require('ReactInstanceMap');
26
ReactTestUtils = require('ReactTestUtils');
@@ -270,4 +272,16 @@ describe('ReactComponent', function() {
272
var instance = ReactTestUtils.renderIntoDocument(element);
273
expect(instance.isMounted()).toBeTruthy();
274
});
275
+
276
+ it('fires the callback after a component is rendered', function() {
277
+ var callback = mocks.getMockFunction();
278
+ var container = document.createElement('div');
279
+ React.render(<div />, container, callback);
280
+ expect(callback.mock.calls.length).toBe(1);
281
+ React.render(<div className="foo" />, container, callback);
282
+ expect(callback.mock.calls.length).toBe(2);
283
+ React.render(<span />, container, callback);
284
+ expect(callback.mock.calls.length).toBe(3);
285
+ });
286
+
287
});