-
Notifications
You must be signed in to change notification settings - Fork 306
6034 - Fix duplicate LazyGrid keys in ChannelMediaAttachmentsGrid #6042
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
base: develop
Are you sure you want to change the base?
6034 - Fix duplicate LazyGrid keys in ChannelMediaAttachmentsGrid #6042
Conversation
...java/io/getstream/chat/android/compose/ui/channel/attachments/ChannelMediaAttachmentsGrid.kt
Outdated
Show resolved
Hide resolved
WalkthroughThe PR modifies item ID generation in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Possibly related issues
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
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: 1
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/state/channel/attachments/ChannelAttachmentsViewState.kt(1 hunks)
...io/getstream/chat/android/ui/common/state/channel/attachments/ChannelAttachmentsViewState.kt
Show resolved
Hide resolved
|
It turns out @andremion To address this, I guess the attachment item ID must also include the attachment’s position within the message. This preserves a stable, deterministic identity for each attachment instance while avoiding UI-derived or non-deterministic fallbacks. This should resolve the remaining duplicate key crashes observed in Compose UI tests. |
🎯 Goal
Fix a crash in
ChannelMediaAttachmentsGridcaused by duplicateLazyVerticalGridkeys during pagination and recomposition.This PR addresses issue #6034.
🛠 Implementation details
ChannelMediaAttachmentsGridusesLazyVerticalGridwith paginated data and a conditional loading item.Previously, grid items used
item.idas the sole key:This is unsafe in this context :
item.idis not guaranteed to be globally uniqueThe loading item had no explicit key
LazyVerticalGridrequires keys to be unique among all currently composed items, including transient items created during paging and recomposition. When this contract is violated, Compose throws anIllegalArgumentExceptionfor duplicate keys.Fix
This preserves stable identity while guaranteeing uniqueness during paging and recomposition.
This prevents key shifting when the loading item is added or removed.
These changes ensure that all grid items - including transient loading items, have stable and unique keys across recompositions and pagination.
🎨 UI Changes
NA
🧪 Testing
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.