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

Keys not unique when grabbing _id's from MongoDB #182

Open
pthieu opened this issue Sep 11, 2017 · 6 comments
Open

Keys not unique when grabbing _id's from MongoDB #182

pthieu opened this issue Sep 11, 2017 · 6 comments
Labels

Comments

@pthieu
Copy link

pthieu commented Sep 11, 2017

I'm getting a unique key conflict, I know this is a react error, but I can seem to debug it. I make sure that all the ID's are unique in each array of children, but this still pops up:

proxyConsole.js:56 Warning: flattenChildren(...): Encountered two children with the same key, `1:$tree-item-59a7227a1d41c83a55289af5`. Child keys must be unique; when two children share a key, only the first child will be used.
    in tbody (created by TableRow)
    in TableRow (created by DragDropContext(TableRow))
    in DragDropContext(TableRow) (created by TableContainer)
    in table (created by TableContainer)
    in div (created by TableContainer)
    in TableContainer (created by Grid)
    in div (created by Grid)
    in Grid (created by Connect(Grid))
    in Connect(Grid) (at ontology-tree.js:55)

My tree looks somewhat like a normal nested tree seen in most of this repo:

[{
  id
  parentId
  name
  children: [{
    id:
    parentId
    name
    children: [{...}, {...}, ...]
  }]
}]

Sometimes the a nested array of children may have some of the same elements as other arrays of children, but every individual array of children will not have duplicated id. Been trying to debug this for a while, is there a way to quickly see what the two conflicts are? I check Redux-Devtools for the conflict but they're not in the state so I can't see which elements are in conflict.

@pthieu
Copy link
Author

pthieu commented Sep 11, 2017

Upon some reading: https://github.com/bencripps/react-redux-grid/blob/master/docs/CREATE_KEY_FROM.md

It seems that even if your child is at another parent, if they have they same _key, it's going to conflict.

What's the correct structure to have the same child in multiple parents: i.e.:

{
  adult1: {
    children: [{
      id: 'child1'
    }]
  }
  adult2: 
    children: [{
      id: 'child1'
    }]
}

Kind of how a child shoes can show up under a parent sports or luxury

@bencripps
Copy link
Owner

In this scenario, since your keys are not unique you shouldn't be specifying the createKeyFrom property. Grid will create unique keys by default (it just won't be as performant).

@pthieu
Copy link
Author

pthieu commented Sep 12, 2017

@bencripps: so would i pass in createKeyFrom: false as a parameter to disable?

@bencripps
Copy link
Owner

That should work, but you could also not pass in the property at all. I believe it defaults to false.

@pthieu
Copy link
Author

pthieu commented Sep 12, 2017

Originally I did not pass it in at all and was still getting this error. Let me try it with it explicitly set to false.

@bencripps
Copy link
Owner

Any update on this?

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

No branches or pull requests

2 participants