Skip to content

Bug: React overwrites functions on customElements #31689

Closed
@mrginglymus

Description

@mrginglymus

React version: 19.0.0

Steps To Reproduce

  1. Define a custom element as shown:
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);
  1. Render
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

The current behavior

this.test is not a function

The expected behavior

React sets attribute as an attribute and does not override function definition

The culprit appears to be this line:

Which does not check to see if the property is a settable property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions