React's handling of custom element properties needs careful consideration.
The issue involves React incorrectly overriding functions on custom elements when setting attributes. The problem is identified in React's DOM property operations, but fixing it requires understanding React's internal handling of properties and attributes. The issue is test-focused, but the solution might impact existing behavior.
React version: 19.0.0
class CEWithAttrPropertyClash extends HTMLElement {
test(value) {
this.dispatchEvent(new CustomEvent('test', {detail: value}))
}
connectedCallback() {
this.test(true);
}
}
customElements.define('ce-with-attr-property-clash', CEWithAttrPropertyClash);
render(<ce-with-attr-property-clash test />);
Link to code example: https://codesandbox.io/p/sandbox/green-resonance-kpwcqg?file=%2Fsrc%2FApp.js%3A10%2C1
this.test is not a function
React sets attribute as an attribute and does not override function definition
The culprit appears to be this line: https://github.com/facebook/react/blob/c56c6234328a29930487295afe61597db48f058c/packages/react-dom-bindings/src/client/DOMPropertyOperations.js#L220
Which does not check to see if the property is a settable property.
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!