Skip to content

Commit

Permalink
Warns when mutated props are passed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed Nov 2, 2015
1 parent 7619214 commit 45a49a0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/renderers/shared/reconciler/ReactCompositeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var emptyObject = require('emptyObject');
var invariant = require('invariant');
var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
var warning = require('warning');
var shallowEqual = require('shallowEqual');

function getDeclarationErrorAddendum(component) {
var owner = component._currentElement._owner || null;
Expand Down Expand Up @@ -147,6 +148,7 @@ var ReactCompositeComponentMixin = {
// Initialize the public class
var inst;
var renderedElement;
var propsMutated;

// This is a way to detect if Component is a stateless arrow function
// component, which is not newable. It might not be 100% reliable but is
Expand Down Expand Up @@ -195,6 +197,15 @@ var ReactCompositeComponentMixin = {
Component.displayName || Component.name || 'Component'
);
}

propsMutated = !shallowEqual(inst.props, publicProps);
if (propsMutated) {
warning(
propsMutated,
'Mutated props not allowed in %s(...)',
Component.displayName || Component.name || 'Component'
);
}
}

// These should be set up in the constructor, but as a convenience for
Expand Down

0 comments on commit 45a49a0

Please sign in to comment.