Skip to content

Broken prototype chain for elements #6580

@ph-fritsche

Description

@ph-fritsche

🐛 bug report

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project
    adheres to.
  • I have searched the issue tracker for an issue that matches the one I want
    to file, without success.

Description of the problem

The class hierarchy for elements is broken.

EventTarget -> Node -> Element -> HTMLElement -> HTMLButtonElement

How has this issue affected you? What are you trying to accomplish?

Using an element as a parameter to e.g. Range.setStart results in TypeError: Failed to execute 'setStart' on 'Range': parameter 1 is not of type 'Node'.

Codesandbox is our primary platform for online reproduction at @testing-library/user-event.
user-event@14 supports Selection. With this bug all pointer interactions with elements that don't implement their own selection (everything except <input>,<textarea>) result in an error.

To Reproduce

test('Element extends Node', () => {
    expect(document.body).toBeInstanceOf(Node) // fails
})

test('select per Range', () => {
    document.body.innerHTML = `<div>foo</div>`

    const range = new Range()
    range.setStart(document.body.firstChild, 0) // throws
    range.setEnd(document.body.firstChild, 1)

    document.getSelection().addRange(range)
})

Link to sandbox: link (optional)

Your Environment

Software Name/Version
Сodesandbox
Browser Chrome 99.0.4844.82
Operating System Ubuntu 20.04.4 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions