diff --git a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
index 37d91f1be0..b07948f0a7 100644
--- a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
+++ b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
@@ -1117,12 +1117,17 @@ var ReactCompositeComponentMixin = {
*/
_renderValidatedComponent: function() {
var renderedComponent;
- ReactCurrentOwner.current = this;
- try {
+ if (__DEV__ || !(this._instance instanceof StatelessComponent)) {
+ ReactCurrentOwner.current = this;
+ try {
+ renderedComponent =
+ this._renderValidatedComponentWithoutOwnerOrContext();
+ } finally {
+ ReactCurrentOwner.current = null;
+ }
+ } else {
renderedComponent =
this._renderValidatedComponentWithoutOwnerOrContext();
- } finally {
- ReactCurrentOwner.current = null;
}
invariant(
// TODO: An `isValidNode` function would probably be more appropriate
diff --git a/src/renderers/shared/stack/reconciler/ReactRef.js b/src/renderers/shared/stack/reconciler/ReactRef.js
index 3ddc23fbd6..a33ca13f1c 100644
--- a/src/renderers/shared/stack/reconciler/ReactRef.js
+++ b/src/renderers/shared/stack/reconciler/ReactRef.js
@@ -62,8 +62,10 @@ ReactRef.shouldUpdateRefs = function(prevElement, nextElement) {
return (
// This has a few false positives w/r/t empty components.
prevEmpty || nextEmpty ||
- nextElement._owner !== prevElement._owner ||
- nextElement.ref !== prevElement.ref
+ nextElement.ref !== prevElement.ref ||
+ // If owner changes but we have an unchanged function ref, don't update refs
+ (typeof nextElement.ref === 'string' &&
+ nextElement._owner !== prevElement._owner)
);
};
diff --git a/src/renderers/shared/stack/reconciler/__tests__/refs-test.js b/src/renderers/shared/stack/reconciler/__tests__/refs-test.js
index 8e2733258a..6811cfe4dc 100644
--- a/src/renderers/shared/stack/reconciler/__tests__/refs-test.js
+++ b/src/renderers/shared/stack/reconciler/__tests__/refs-test.js
@@ -240,5 +240,39 @@ describe('ref swapping', function() {
var instance = ReactTestUtils.renderIntoDocument();
expect(!!instance.refs).toBe(true);
});
+
+ function testRefCall() {
+ var refCalled = 0;
+ function Inner(props) {
+ return ;
+ }
+ var Outer = React.createClass({
+ saveA() {
+ refCalled++;
+ },
+ componentDidMount() {
+ this.setState({});
+ },
+ render() {
+ return ;
+ },
+ });
+ ReactTestUtils.renderIntoDocument();
+ expect(refCalled).toBe(1);
+ }
+
+ it('ref called correctly for stateless component when __DEV__ = false', function() {
+ var originalDev = __DEV__;
+ __DEV__ = false;
+ testRefCall();
+ __DEV__ = originalDev;
+ });
+
+ it('ref called correctly for stateless component when __DEV__ = true', function() {
+ var originalDev = __DEV__;
+ __DEV__ = true;
+ testRefCall();
+ __DEV__ = originalDev;
+ });
});