codesandbox / codesandbox/codesandbox-client

Broken prototype chain for elements

Open
#6,580 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
13.6k
Forks
2.4k
Avg merge
6d 19h
Merged PRs (30d)
2

Description

🐛 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided reproduction tests and the linked CodeSandbox, focusing on document.body, Node, Range.setStart, and Range.setEnd. Confirm the broken prototype relationship and Range failures, then verify that elements follow EventTarget → Node → Element and that both range operations accept the reproduced element or text-node inputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.