Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selection.selectChildren().remove() does not remove all children #275

Closed
KirkMcDonald opened this issue Feb 2, 2021 · 1 comment · Fixed by #276
Closed

selection.selectChildren().remove() does not remove all children #275

KirkMcDonald opened this issue Feb 2, 2021 · 1 comment · Fixed by #276
Labels

Comments

@KirkMcDonald
Copy link

For example, given the following HTML:

<div id="content">
    <span>0</span>
    <span>1</span>
    <span>2</span>
    <span>3</span>
    <span>4</span>
    <span>5</span>
    <span>6</span>
    <span>7</span>
    <span>8</span>
    <span>9</span>
</div>

The expression d3.select("#content").selectChildren().remove() will only remove the even-numbered elements. I find this behavior surprising, and would naively expect it to remove all of the <span> tags.

In contrast, the expression d3.select("#content").selectAll("*").remove() will remove all of the <span> tags.

@Fil Fil added the bugfix label Feb 2, 2021
Fil added a commit that referenced this issue Feb 2, 2021
@Fil Fil mentioned this issue Feb 2, 2021
@Fil
Copy link
Member

Fil commented Feb 2, 2021

Good catch! Maybe a solution would be to materialize Array.from(...this.children) instead of this.children, because remove calls each with a function which mutates this.children.

I've implemented this in #276, it passes all tests but I'm not 100% sure it's the right approach.

mbostock pushed a commit that referenced this issue Jun 7, 2021
mbostock added a commit that referenced this issue Jun 7, 2021
* remove all children

fixes #275

* more defensive copy selectAll

* comment array

Co-authored-by: Mike Bostock <mbostock@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 participants