From 2702281a130e8118b70fcd37f71d22b49f5fd837 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Mon, 2 Feb 2015 20:42:15 -0800 Subject: [PATCH] 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. --- src/core/ReactUpdateQueue.js | 1 + src/core/__tests__/ReactComponent-test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/core/ReactUpdateQueue.js b/src/core/ReactUpdateQueue.js index 7562fea8cf..ec1ac00f9e 100644 --- a/src/core/ReactUpdateQueue.js +++ b/src/core/ReactUpdateQueue.js @@ -111,6 +111,7 @@ var ReactUpdateQueue = { } else { internalInstance._pendingCallbacks = [callback]; } + enqueueUpdate(internalInstance); }, /** diff --git a/src/core/__tests__/ReactComponent-test.js b/src/core/__tests__/ReactComponent-test.js index 350f369306..c09376a27f 100644 --- a/src/core/__tests__/ReactComponent-test.js +++ b/src/core/__tests__/ReactComponent-test.js @@ -15,10 +15,12 @@ var React; var ReactInstanceMap; var ReactTestUtils; +var mocks; var reactComponentExpect; describe('ReactComponent', function() { beforeEach(function() { + mocks = require('mocks'); React = require('React'); ReactInstanceMap = require('ReactInstanceMap'); ReactTestUtils = require('ReactTestUtils'); @@ -270,4 +272,16 @@ describe('ReactComponent', function() { var instance = ReactTestUtils.renderIntoDocument(element); expect(instance.isMounted()).toBeTruthy(); }); + + it('fires the callback after a component is rendered', function() { + var callback = mocks.getMockFunction(); + var container = document.createElement('div'); + React.render(
, container, callback); + expect(callback.mock.calls.length).toBe(1); + React.render(
, container, callback); + expect(callback.mock.calls.length).toBe(2); + React.render(, container, callback); + expect(callback.mock.calls.length).toBe(3); + }); + });