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

children method does not return duplicate children #1275

Closed
WeishenMead opened this issue Oct 17, 2017 · 3 comments
Closed

children method does not return duplicate children #1275

WeishenMead opened this issue Oct 17, 2017 · 3 comments

Comments

@WeishenMead
Copy link

WeishenMead commented Oct 17, 2017

Calling node.children() does not always return duplicate children (instead it removes them). It looks like this is because children uses flatMap internally, and flatMap dedupes its entries.

Somewhat trivial test case:

render() {
  const foo = 'Foo';
  return (
    <div>
      {foo} Bar {foo} Bar {foo}
    </div>
  )
}

In this case I would expect:
node.children() === ['Foo', 'Bar', 'Foo', 'Bar', 'Foo']

but instead we get:
node.children() === ['Foo', 'Bar']

I tested this in version 2.9.1, but looking at the code I think it should still exist in master.

I think the right solution is to not use de-dupe in flatMap, but I'm not sure if there's a reason that was added in to begin with.

@ljharb
Copy link
Member

ljharb commented Oct 17, 2017

Indeed, deduping in flatMap seems weird.

@ljharb ljharb added the bug label Oct 17, 2017
@ljharb
Copy link
Member

ljharb commented Oct 17, 2017

Is this in shallow, mount, or both? Can you replicate it using v3?

@WeishenMead
Copy link
Author

I replicated in shallow. I'll update the initial post with that. I haven't tried v3 (I took a quick look at the code and it seemed like this should still happen in v3 though).

I'll try to test with mount and see if it's there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants