marmelab / react-admin

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design
http://marmelab.com/react-admin
MIT License
25k stars 5.26k forks source link

ArrayField + SingleFieldList: if embedded data doesn't have an id, rows won't have a key and will cause a React warning #7614

Closed smeng9 closed 2 years ago

smeng9 commented 2 years ago

What you were expecting:

Using an ArrayField + SingleFieldListfor embedded data that doesn't have an id prop should work without console errors

What happened instead:

I get this error in the console: Warning: Each child in a list should have a unique "key" prop.

Steps to reproduce:

  1. Goto https://hs0dpi.sse.codesandbox.io/#/posts/12/show
  2. Open console to see the warning

Related code:

https://codesandbox.io/s/stoic-glade-hs0dpi?file=/src/posts/PostShow.tsx:1269-1446

Other information:

This is where the key is set based on the id, which doesn't exist in this case:

https://github.com/marmelab/react-admin/blob/master/packages/ra-ui-materialui/src/list/SingleFieldList.tsx#L102

Environment

smeng9 commented 2 years ago

Duplicate of https://github.com/marmelab/react-admin/issues/7541

The fix should be similar to https://github.com/marmelab/react-admin/pull/7548 and just one or two lines