Guard against contentEditable with children props
Andreas Svensson committed
May 12, 2014 at 22:25 UTC
3bec9f070fa0de5c749f91a9bcbf7a901135cb8f
2 files changed
+27
src/browser/ui/ReactDOMComponent.js
+10
@@ -58,6 +58,16 @@ function assertValidProps(props) {
58
props.children == null || props.dangerouslySetInnerHTML == null,
59
'Can only set one of `children` or `props.dangerouslySetInnerHTML`.'
60
);
61
+ if (__DEV__) {
62
+ if (props.contentEditable && props.children != null) {
63
+ console.warn(
64
+ 'A component is `contentEditable` and contains `children` managed by ' +
65
+ 'React. It is now your responsibility to guarantee that none of those '+
66
+ 'nodes are unexpectedly modified or duplicated. This is probably not ' +
67
+ 'intentional.'
68
+ );
69
+ }
70
+ }
71
invariant(
72
props.style == null || typeof props.style === 'object',
73
'The `style` prop expects a mapping from style properties to values, ' +
src/browser/ui/__tests__/ReactDOMComponent-test.js
+17
@@ -335,6 +335,13 @@ describe('ReactDOMComponent', function() {
335
);
336
});
337
338
+ it("should warn about contentEditable and children", function() {
339
+ spyOn(console, 'warn');
340
+ mountComponent({ contentEditable: true, children: '' });
341
+ expect(console.warn.argsForCall.length).toBe(1);
342
+ expect(console.warn.argsForCall[0][0]).toContain('contentEditable');
343
+ });
344
+
345
it("should validate against invalid styles", function() {
346
expect(function() {
347
mountComponent({ style: 'display: none' });
@@ -368,6 +375,16 @@ describe('ReactDOMComponent', function() {
375
);
376
});
377
378
+ it("should warn about contentEditable and children", function() {
379
+ spyOn(console, 'warn');
380
+ React.renderComponent(
381
+ <div contentEditable><div /></div>,
382
+ container
383
+ );
384
+ expect(console.warn.argsForCall.length).toBe(1);
385
+ expect(console.warn.argsForCall[0][0]).toContain('contentEditable');
386
+ });
387
+
388
it("should validate against invalid styles", function() {
389
React.renderComponent(<div></div>, container);
390