chore(web): use stable keys for mapped lists#593
chore(web): use stable keys for mapped lists#593grzdev wants to merge 1 commit intoaccomplish-ai:mainfrom
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughReact list rendering keys are being updated from simple numeric indices to composite identifiers in two components. DebugPanel uses timestamp-type-index combinations for log rows and part-index composites for highlights, while Home.tsx applies the use case example's key property to its rendered list. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/web/src/client/components/execution/DebugPanel.tsx (1)
266-268: Composite key improves stability but retains index dependency.The key
${log.timestamp}-${log.type}-${index}is an improvement over a bare index. However, sinceindexis derived fromfilteredDebugLogs, when the search query changes, the same log entry may receive a different key (e.g., if it shifts from position 5 to position 2 in filtered results).If
DebugLogEntryhad a uniqueidfield, usinglog.idalone would provide fully stable keys across filter changes. For now, this implementation is acceptable since the timestamp-type prefix provides partial stability within consistent filter states.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/src/client/components/execution/DebugPanel.tsx` around lines 266 - 268, The current key for items in the filteredDebugLogs map uses the index (`key={`${log.timestamp}-${log.type}-${index}`}`), which can change when filters/searches reorder results; update the mapping to use a stable unique identifier instead—add an `id` field to the DebugLogEntry type and populate it when logs are created/loaded, then use `log.id` as the React key in the map (fallback: if you cannot add ids right now, remove the index and use the stable composite `\`${log.timestamp}-${log.type}\`` to reduce churn); update references in the component where filteredDebugLogs is iterated to use the new `log.id` key.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/src/client/components/execution/DebugPanel.tsx`:
- Around line 266-268: The current key for items in the filteredDebugLogs map
uses the index (`key={`${log.timestamp}-${log.type}-${index}`}`), which can
change when filters/searches reorder results; update the mapping to use a stable
unique identifier instead—add an `id` field to the DebugLogEntry type and
populate it when logs are created/loaded, then use `log.id` as the React key in
the map (fallback: if you cannot add ids right now, remove the index and use the
stable composite `\`${log.timestamp}-${log.type}\`` to reduce churn); update
references in the component where filteredDebugLogs is iterated to use the new
`log.id` key.
8f55620 to
096680b
Compare
Description
Replaces "key={index}" usage with stable, content-based keys in "Home.tsx" and "DebugPanel.tsx".
Using array indices as keys can cause React reconciliation issues when items are reordered or dynamically updated. This change uses stable identifiers derived from content instead.
No functional behavior changes.
Type of Change
feat: New feature or functionalityfix: Bug fixdocs: Documentation only changeschore: Maintenance, dependencies, or toolingrefactor: Code refactoring (no feature change)test: Adding or updating testsperf: Performance improvementci: CI/CD changesChecklist
feat: add dark mode support)Related Issues
No related Issues.
Summary by CodeRabbit