Fix inline reader/highlight drifting to wrong article after refresh#205
Merged
disnet merged 1 commit intoMay 14, 2026
Merged
Conversation
When a refresh re-sorted the visible list (e.g. new articles arrive during auto-poll), the inline reader / expanded card was tied to the array index of the originally-selected item. New items pushed the selected item to a higher index, so the highlight, inline preview, and mark-as-read all latched onto the wrong card. Switch the source of truth for selection and expansion from a numeric index to FeedDisplayItem.key (already the keyed-each key, stable per item). selectedIndex / expandedIndex are kept as derived getters so existing call sites that need an index (scrollToCenter, j/k navigation) keep working. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FeedDisplayItem.keyinstead of by array index, so refresh-driven re-sorts no longer move the inline reader / highlight onto a different article.selectedIndex/expandedIndexas derived getters so existing call sites that need an index (scroll-to-center, j/k navigation) keep working.Why
If you click on an article in a channel and read it inline, then trigger (or auto-receive) a refresh that brings new articles in, the existing index-based selection stays put — but the array has been re-sorted by
publishedAt, so the highlighted slot now belongs to a different article. The originally-clicked article appears un-expanded at its new index and is also marked-as-read because of the resolved selection. #204Changes
frontend/src/lib/stores/feedView.svelte.tsselectedIndex/expandedIndexstate withselectedKey/expandedKey(string | null).selectByKey(key); rewriteselect(index)to resolve the index to a key viacurrentItems.selectedKey/expandedKeyand keepselectedIndex/expandedIndexas derived getters (findIndexagainstcurrentItems).frontend/src/lib/components/feed/FeedListView.sveltedisplayItem.key.openSelectedReaderresolves the item by key.frontend/src/lib/components/feed/SavedListView.svelteSavedCard.selected.openSelectedReaderresolves by key.frontend/src/lib/hooks/useFeedKeyboardShortcuts.svelte.tsgetSelectedItem()helper that looks up the selected item byselectedKey.findIndex(i => i.key === selectedKey)to preservej/kbehaviour.hasSelected()now checksselectedKey !== null; thehcondition checksexpandedKey !== null.Notes / risks
readerItemalready stored the item object directly; the fullscreen reader was never affected, only the list highlight and the inline preview.selectedKeywill not find a match incurrentItemsand the derivedselectedIndexreturns-1— same observable state as before.FeedDisplayItem.keyis already trusted as unique by the keyed#eachin both list views; no new uniqueness assumption.Test plan
cd frontend && npm run check(passes, 0 errors)j/kand confirm selection moves from the correct current article.SavedListView.🤖 Generated with Claude Code