Skip to content

selection.data() throws TypeError when selection is created from a DOM element #324

Description

@Danial-Sadiq-Masood

Description

Calling data() on a selection created from a DOM element appears to fail when D3 attempts to create EnterNodes.
The following works:

d3.select('#app').data([1, 2, 3, 4]);

but the equivalent selection created from the DOM element itself throws:

d3.select(document.getElementById('app')).data([1, 2, 3, 4]);

Uncaught TypeError: Cannot read properties of null (reading 'ownerDocument') at new EnterNode (d3-selection.js?v=2f31b0b4:142:30) at bindIndex (d3-selection.js?v=2f31b0b4:177:20)...

Shouldn't both snippets result in indentical execution?

Reproduction

<div id="app"></div>
<script>
  d3.select(document.getElementById('app'))
    .data([1, 2, 3, 4]);
</script>

Environment

d3-selection : 3.0.0
browser : Chrome Version 147.0.7727.55 (Official Build) (64-bit)

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