Fixed duplicate key issue#3452
Conversation
🧪 Unit Test Results📊 Summary
Last updated: Thu, 18 Dec 2025 09:39:26 GMT |
There was a problem hiding this comment.
Review Summary
This PR modifies the key generation strategy for LazyColumn items in the ToDoList screen. While the intention appears to be solving duplicate key issues, the implementation has concerns that should be addressed.
Issues Found
- Key uses
indexwhich breaks Compose's state preservation (line 375)- Using array indices in keys causes state loss and animation issues when list order changes
- Compose keys should be stable and tied to item identity, not position
- See inline comment for recommended solutions
What Works Well
✅ Good attempt to ensure key uniqueness by combining multiple properties
✅ Maintains the existing item rendering logic without changes
Recommendations
-
Investigate the root cause: Why is
item.idnot sufficient as a unique key? This should be addressed at the data layer. -
If items can appear in multiple date groups: Use
"${date.time}_${item.id}"without the index. -
If item.id truly isn't unique: This indicates a data model problem that should be fixed rather than worked around with indices.
-
Add a comment: If there's a specific reason for this key structure, document it so future maintainers understand the rationale.
Testing Suggestions
- Verify list reordering works correctly (if applicable)
- Test filtering/sorting to ensure items maintain their state
- Check for any animation glitches when items move positions
Let me know if you need clarification on the Jetpack Compose key semantics or help investigating the duplicate key issue!
Test plan: Use a proxy to generate a To Do list response that contains two items with the same id.