Skip to content

Commit 3bec9f0

Browse files
committed
Guard against contentEditable with children props
1 parent 32b84a4 commit 3bec9f0

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/browser/ui/ReactDOMComponent.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ function assertValidProps(props) {
5858
props.children == null || props.dangerouslySetInnerHTML == null,
5959
'Can only set one of `children` or `props.dangerouslySetInnerHTML`.'
6060
);
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+
}
6171
invariant(
6272
props.style == null || typeof props.style === 'object',
6373
'The `style` prop expects a mapping from style properties to values, ' +

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ describe('ReactDOMComponent', function() {
335335
);
336336
});
337337

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+
338345
it("should validate against invalid styles", function() {
339346
expect(function() {
340347
mountComponent({ style: 'display: none' });
@@ -368,6 +375,16 @@ describe('ReactDOMComponent', function() {
368375
);
369376
});
370377

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+
371388
it("should validate against invalid styles", function() {
372389
React.renderComponent(<div></div>, container);
373390

0 commit comments

Comments
 (0)