-
Notifications
You must be signed in to change notification settings - Fork 646
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
Fix: Ensure unique keys for comments in ResourceCommentSection #11125
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request updates the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/components/Resource/ResourceCommentSection.tsx (1)
97-103
: Improved key management in the comment list.The change to use
comment.id || index
as a key is a good fix that ensures each item in the list has a unique identifier, even when a comment might not have an ID. This addresses potential React reconciliation issues and follows best practices for rendering lists.The code formatting improvements (breaking the method chain into separate lines) also enhance readability.
Consider adding a warning log when
comment.id
is undefined, as this might indicate an upstream data issue that should be addressed:{resourceComments?.results ? [...resourceComments.results] .reverse() .map((comment, index) => ( - <li key={comment.id || index} className="w-full"> + <li key={comment.id || index} className="w-full"> + {!comment.id && console.warn('Comment missing ID, using index as fallback key', comment)} <Comment {...comment} /> </li> )) : null}
? [...resourceComments.results] | ||
.reverse() | ||
.map((comment, index) => ( | ||
<li key={comment.id || index} className="w-full"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 What exactly is this addressing? It shouldn't be causing issues since comments will always have a unique Id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ensures that if at any point comment.id is null or undefined it will fallback to another unique key called index rather than using undefined, which could cause rendering issues in React.
Proposed Changes
Fixed the unique key prop issue in ResourceCommentSection.tsx
@ohcnetwork/care-fe-code-reviewers
Merge Checklist
Summary by CodeRabbit
Bug Fixes
Style