Skip to content

Item: chance of auto-generated key collision when using shorthand props #2418

Description

@noinkling

Steps

<Item header="1984" meta="1984" />

// or even:
<Item>
  <Item.Content header="1984" meta={1984} />
</Item>

Expected Result

No issues.

Actual Result

Warning: Encountered two children with the same key, `1984`. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

The warning is caused by the keys being automatically set from the value, here:

} else if (valIsString || valIsNumber) {
// use string/number shorthand values as the key
props.key = val
}

Note that there's no need for keys at all in this example.

One workaround that prevents the keys from being set (and therefore the error):

<Item header={{ content: "1984" }} meta={{ content: "1984" }} />
// yuck

Version

0.77.1

Testcase

https://codesandbox.io/s/4r702vq8y4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions