Skip to content

fix(react): add missing unique key props to ChatInputFormattingToolba…#1102

Merged
Spiral-Memory merged 1 commit intoRocketChat:developfrom
deepak0x:fix/toolbar-key-prop
Mar 21, 2026
Merged

fix(react): add missing unique key props to ChatInputFormattingToolba…#1102
Spiral-Memory merged 1 commit intoRocketChat:developfrom
deepak0x:fix/toolbar-key-prop

Conversation

@deepak0x
Copy link
Copy Markdown
Contributor

@deepak0x deepak0x commented Jan 24, 2026

This PR fixes a common React warning:

Warning: Each child in a list should have a unique "key" prop

The warning occurred in the ChatInputFormattingToolbar component and was caused by several elements being rendered as part of dynamic lists without providing a unique key prop. This made it harder for React to correctly track and optimize updates to these elements.


Closes #1098

Changes

Updated packages/react/src/views/ChatInput/ChatInputFormattingToolbar.js:

  • Added key="audio" to the AudioMessageRecorder component.
  • Added key="video" to the VideoMessageRecorder component.
  • Replaced empty fragments (<>) with <React.Fragment key={item.name}> for mapped formatting buttons (bold, italic, strike, etc.).

@sudorishabh
Copy link
Copy Markdown

Bro, I saw the same issue earlier and searched to see if there was already an open PR. I came across your implementation. Great work. However, there’s a small improvement that can be made. You don’t actually need <React.Fragment> here. React only cares about the key on the top-level element returned from the map. Since the key is already on the component, the fragment is unnecessary and can be removed entirely.

Copy link
Copy Markdown
Collaborator

@Spiral-Memory Spiral-Memory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Spiral-Memory Spiral-Memory merged commit 2401520 into RocketChat:develop Mar 21, 2026
4 checks passed
@Spiral-Memory Spiral-Memory added the chore a subtle fix label Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore a subtle fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Missing unique "key" prop in ChatInputFormattingToolbar components

3 participants