Skip to content

Commit edc0fa4

Browse files
Cheng Louzpao
authored andcommitted
assertValidProps for updating DOM components through renderComponent
`renderComponent(<div style={invalidType}/>, container)` throws correctly, but not when it's called a second time (i.e. updating rather than mounting). It goes through `ReactDOMComponent.updateComponent` but there wasn't a props assertion there. (Removed the assertion in `receiveComponent`)
1 parent 116ee05 commit edc0fa4

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/browser/ui/ReactDOMComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ ReactDOMComponent.Mixin = {
215215
return;
216216
}
217217

218-
assertValidProps(nextComponent.props);
219218
ReactComponent.Mixin.receiveComponent.call(
220219
this,
221220
nextComponent,
@@ -236,6 +235,7 @@ ReactDOMComponent.Mixin = {
236235
'ReactDOMComponent',
237236
'updateComponent',
238237
function(transaction, prevProps, prevOwner) {
238+
assertValidProps(this.props);
239239
ReactComponent.Mixin.updateComponent.call(
240240
this,
241241
transaction,

src/browser/ui/__tests__/ReactDOMComponent-test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,41 @@ describe('ReactDOMComponent', function() {
340340
});
341341
});
342342

343+
describe('updateComponent', function() {
344+
var React;
345+
var container;
346+
347+
beforeEach(function() {
348+
React = require('React');
349+
container = document.createElement('div');
350+
});
351+
352+
it("should validate against multiple children props", function() {
353+
React.renderComponent(<div></div>, container);
354+
355+
expect(function() {
356+
React.renderComponent(
357+
<div children="" dangerouslySetInnerHTML={{__html: ''}}></div>,
358+
container
359+
);
360+
}).toThrow(
361+
'Invariant Violation: Can only set one of `children` or ' +
362+
'`props.dangerouslySetInnerHTML`.'
363+
);
364+
});
365+
366+
it("should validate against invalid styles", function() {
367+
React.renderComponent(<div></div>, container);
368+
369+
expect(function() {
370+
React.renderComponent(<div style={1}></div>, container);
371+
}).toThrow(
372+
'Invariant Violation: The `style` prop expects a mapping from style ' +
373+
'properties to values, not a string.'
374+
);
375+
});
376+
});
377+
343378
describe('unmountComponent', function() {
344379
it("should clean up listeners", function() {
345380
var React = require('React');

0 commit comments

Comments
 (0)