fix(web): keep highlights card active index in range on refresh#1334
Open
abhay-codes07 wants to merge 1 commit into
Open
fix(web): keep highlights card active index in range on refresh#1334abhay-codes07 wants to merge 1 commit into
abhay-codes07 wants to merge 1 commit into
Conversation
The Daily Brief refreshes on its own every few hours, replacing the items array, and the paging controls also let the user sit on a later index. When a refresh returns fewer highlights than before, activeIndex was left pointing past the end of the new list, so currentItem became undefined and the card rendered the "Add some documents" empty state even though highlights existed, with no pagination shown to recover from it. Clamp activeIndex back into range whenever items changes, alongside the existing reply/expansion reset. Also drops a now-unnecessary useExhaustiveDependencies suppression, since the effect body now reads items.length so items is a real dependency.
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.
Problem
HighlightsCardtracks the visible highlight withactiveIndex, and derivescurrentItem = items[activeIndex]. Whenitemschanges, the effect keyed on[items]resets the reply and expansion state but never touchesactiveIndex:The Daily Brief "refreshes automatically every few hours" (per the card's own info popover), which replaces
itemswholesale. If the user has paged to a later highlight and the refresh returns a shorter list,activeIndexis left pointing past the end.currentItembecomesundefined, and the render falls through to:So the card shows the empty "add documents" state even though highlights exist. The pagination row is only rendered in the populated branch, so there is no visible control to page back into range — the card stays stuck on the empty state until it remounts.
Repro
activeIndex > 0).activeIndex + 1.Result on
main: the card renders "Add some documents to see highlights here" despite having highlights, with no way to recover in-place. The same happens for any parent that swapsitemsfor a shorter array while the user is on a later page.Fix
Clamp
activeIndexinto range wheneveritemschanges, next to the existing reset:This keeps the current position when it is still valid and only pulls it back when the list shrank. When
itemsis genuinely empty it resolves to0, and the existingitems.length === 0guard renders the empty state correctly.Also removes a
useExhaustiveDependenciessuppression that is no longer needed: the effect body now readsitems.length, soitemsis a real dependency rather than a suppressed one.No test is included because
apps/webhas no component test harness set up; the change is a two-line clamp mirroring the same pattern used elsewhere for selection bounds. cc @MaheshtheDev @ishaanxgupta