Skip to content

Commit c14b3a1

Browse files
committed
Merge pull request react#1520 from syranide/ediblechildren
Warn against contentEditable with children props
2 parents 65c1834 + 3bec9f0 commit c14b3a1

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/browser/ui/ReactDOMComponent.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ function assertValidProps(props) {
6060
props.children == null || props.dangerouslySetInnerHTML == null,
6161
'Can only set one of `children` or `props.dangerouslySetInnerHTML`.'
6262
);
63+
if (__DEV__) {
64+
if (props.contentEditable && props.children != null) {
65+
console.warn(
66+
'A component is `contentEditable` and contains `children` managed by ' +
67+
'React. It is now your responsibility to guarantee that none of those '+
68+
'nodes are unexpectedly modified or duplicated. This is probably not ' +
69+
'intentional.'
70+
);
71+
}
72+
}
6373
invariant(
6474
props.style == null || typeof props.style === 'object',
6575
'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
@@ -346,6 +346,13 @@ describe('ReactDOMComponent', function() {
346346
);
347347
});
348348

349+
it("should warn about contentEditable and children", function() {
350+
spyOn(console, 'warn');
351+
mountComponent({ contentEditable: true, children: '' });
352+
expect(console.warn.argsForCall.length).toBe(1);
353+
expect(console.warn.argsForCall[0][0]).toContain('contentEditable');
354+
});
355+
349356
it("should validate against invalid styles", function() {
350357
expect(function() {
351358
mountComponent({ style: 'display: none' });
@@ -379,6 +386,16 @@ describe('ReactDOMComponent', function() {
379386
);
380387
});
381388

389+
it("should warn about contentEditable and children", function() {
390+
spyOn(console, 'warn');
391+
React.renderComponent(
392+
<div contentEditable><div /></div>,
393+
container
394+
);
395+
expect(console.warn.argsForCall.length).toBe(1);
396+
expect(console.warn.argsForCall[0][0]).toContain('contentEditable');
397+
});
398+
382399
it("should validate against invalid styles", function() {
383400
React.renderComponent(<div></div>, container);
384401

0 commit comments

Comments
 (0)