Skip to content

Commit af292bc

Browse files
committed
Add innerText and textContent to reservedProps
1 parent 9bec8b1 commit af292bc

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/react-dom/src/__tests__/DOMPropertyOperations-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,32 @@ describe('DOMPropertyOperations', () => {
263263
.dispatchEvent(new Event('customevent', {bubbles: false}));
264264
expect(oncustomevent).toHaveBeenCalledTimes(1);
265265
});
266+
267+
it('innerHTML should not work on custom elements', () => {
268+
const container = document.createElement('div');
269+
ReactDOM.render(<my-custom-element innerHTML="foo" />, container);
270+
const customElement = container.querySelector('my-custom-element');
271+
expect(customElement.getAttribute('innerHTML')).toBe(null);
272+
expect(customElement.hasChildNodes()).toBe(false);
273+
});
274+
275+
// @gate enableCustomElementPropertySupport
276+
it('innerText should not work on custom elements', () => {
277+
const container = document.createElement('div');
278+
ReactDOM.render(<my-custom-element innerText="foo" />, container);
279+
const customElement = container.querySelector('my-custom-element');
280+
expect(customElement.getAttribute('innerText')).toBe(null);
281+
expect(customElement.hasChildNodes()).toBe(false);
282+
});
283+
284+
// @gate enableCustomElementPropertySupport
285+
it('textContent should not work on custom elements', () => {
286+
const container = document.createElement('div');
287+
ReactDOM.render(<my-custom-element textContent="foo" />, container);
288+
const customElement = container.querySelector('my-custom-element');
289+
expect(customElement.getAttribute('textContent')).toBe(null);
290+
expect(customElement.hasChildNodes()).toBe(false);
291+
});
266292
});
267293

268294
describe('deleteValueForProperty', () => {

packages/react-dom/src/shared/DOMProperty.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import {enableFilterEmptyStringAttributesDOM} from 'shared/ReactFeatureFlags';
10+
import {enableFilterEmptyStringAttributesDOM, enableCustomElementPropertySupport} from 'shared/ReactFeatureFlags';
1111
import hasOwnProperty from 'shared/hasOwnProperty';
1212

1313
type PropertyType = 0 | 1 | 2 | 3 | 4 | 5 | 6;
@@ -266,6 +266,9 @@ const reservedProps = [
266266
'suppressHydrationWarning',
267267
'style',
268268
];
269+
if (enableCustomElementPropertySupport) {
270+
reservedProps.push('innerText', 'textContent');
271+
}
269272

270273
reservedProps.forEach(name => {
271274
properties[name] = new PropertyInfoRecord(

0 commit comments

Comments
 (0)