Skip to content

fix(search): crash when tapping a recent search ("Key was already used") - #89

Merged
Lennoard merged 1 commit into
Lennoard:developfrom
Glucy-2:fix/search-history-duplicate-key
Nov 7, 2026
Merged

Lennoard merged 1 commit into
Lennoard:developfrom
Glucy-2:fix/search-history-duplicate-key

Conversation

@Glucy-2

@Glucy-2 Glucy-2 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Problem

Tapping a recent-search entry in the search screen can crash the app:

java.lang.IllegalArgumentException: Key "history:net.ipv4.tcp_congestion_control" was already used. If you are using LazyColumn/Row please make sure you provide a unique key for each item.

Cause

SearchViewModel.handleSearch appends every query to the in-memory searchHistory list without checking for duplicates. The persisted history (AppPrefs.searchHistory) is a Set, so the duplicate only exists until the app restarts. After a term is searched while already present in the history (for example by tapping a recent search), the list holds two identical entries. SearchScreen uses "history:${it.hint}" as the LazyColumn item key, so the next time the hints are shown, Compose throws.

Fix

Remove an existing entry before adding the query (searchHistory.remove(query) in SearchViewModel.handleSearch), so the in-memory list stays unique like the persisted Set.

Testing

Built a debug APK from this branch and ran it on a device (Android 17, arm64): with one saved history item, opened search, tapped the search box, then tapped the recent search 3 times in a row. The app stayed alive and logcat showed no FATAL EXCEPTION. Before the change the first tap crashed with the exception above.

@Lennoard Lennoard added the bug Something isn't working label Nov 7, 2026
@Lennoard Lennoard self-assigned this Nov 7, 2026
@Lennoard
Lennoard merged commit fecf135 into Lennoard:develop Nov 7, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants