meilisearch-react icon indicating copy to clipboard operation
meilisearch-react copied to clipboard

Each child in a list should have a unique "key" prop.

Open CaroFG opened this issue 1 year ago • 8 comments

Description Description of what the bug is about. Using the provided example we get a react warning:

Each child in a list should have a unique "key" prop.

Check the render method of `Hits`. See https://reactjs.org/link/warning-keys for more information.

Expected behavior What you expected to happen. The example should provide a unique key to each hit, so that the warning is not triggered.

Current behavior What happened. The code sandbox hit component has a key property, but it does not remove the warning:

const Hit = ({ hit }) => (
  <div key={hit.id}>
    <div className="hit-name">
      <Highlight attribute="name" hit={hit} />
    </div>
    <img src={hit.image} align="left" alt={hit.name} />
    <div className="hit-description">
      <Snippet attribute="description" hit={hit} />
    </div>
    <div className="hit-info">price: {hit.price}</div>
    <div className="hit-info">release date: {hit.releaseDate}</div>
  </div>
);

Screenshots or Logs If applicable, add screenshots or logs to help explain your problem. Screenshot 2024-04-23 at 15 07 52

Environment (please complete the following information):

  • OS: [e.g. Debian GNU/Linux]
  • Browser: [e.g. Chrome version 90.0]
  • Meilisearch version: [e.g. v.0.20.0]
  • instant-meilisearch version: [e.g. v0.5.0]
  • react-instantsearch version: [e.g. v6.10.3]
  • React version: [e.g. 16.13.1]

CaroFG avatar Apr 23 '24 13:04 CaroFG

@CaroFG are you sure it does not come from react-isntantsearch, so on the algolia side?

curquiza avatar Apr 23 '24 14:04 curquiza

A user said it appeared when he moved from Algolia to Meilisearch, see Discord. As I told the user, I guess Algolia uses by default the objectID they generate for each document, but since we don't use an objectID we should probably provide an example that does not trigger a warning.

CaroFG avatar Apr 23 '24 14:04 CaroFG

Thanks for the context! Pinging this as good first issue

curquiza avatar Apr 23 '24 16:04 curquiza

Hello, may I work on this issue?

replyre avatar Apr 24 '24 06:04 replyre

Go ahead @replyre!

CaroFG avatar Apr 24 '24 10:04 CaroFG

Hi @replyre. any news?)

voronovmaksim avatar Aug 21 '24 12:08 voronovmaksim

Hello @voronovmaksim Not done yet, we are waiting for a PR 😊

curquiza avatar Aug 21 '24 13:08 curquiza

hey @voronovmaksim, I looked through it but wasn't able to find the root of the issue. Sorry, I forgot to mention it earlier. I will look at it again if you wish on Saturday, as I'm busy right now. Thank you for your patience.

replyre avatar Aug 22 '24 10:08 replyre

Had the same error. According to the instant-meilisearch readme, we need to add the primary key in the client config like so:

const {searchClient} = instantMeiliSearch(
    'http://localhost:7700/',
    'masterKey',
    {
        primaryKey: 'id',
        finitePagination: true,
    }
)

and the error was gone.

dc-p8 avatar Mar 02 '25 18:03 dc-p8