Skip to content

fix: filter changes no longer blank the event list - #114

Merged
Abd-Standard merged 1 commit into
Core-Foundry:mainfrom
michaelvic123:fix/filter-resets-pagination
Jun 20, 2026
Merged

fix: filter changes no longer blank the event list#114
Abd-Standard merged 1 commit into
Core-Foundry:mainfrom
michaelvic123:fix/filter-resets-pagination

Conversation

@michaelvic123

@michaelvic123 michaelvic123 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

closes #87

Root cause

The virtual list computes its visible window using scrollTop (a React state value). When a filter is applied and the event list shrinks, the scroll reset happens in a useEffect — which runs after the render. On that first render with the new shorter list, the stale scrollTop produces a startIndex beyond the end of the filtered array, so events.slice(startIndex, endIndex) returns [] and the list goes blank.

Fix

Clamp scrollTop to the maximum valid scroll offset before computing startIndex inside the useMemo. This is a pure calculation change — one extra line — and makes the windowing logic correct regardless of effect timing.

const maxScrollTop = Math.max(0, events.length * ROW_HEIGHT - viewportHeight);
const clampedScrollTop = Math.min(scrollTop, maxScrollTop);
const startIndex = Math.max(0, Math.floor(clampedScrollTop / ROW_HEIGHT) - OVERSCAN);

Tests added

  • applies a filter while scrolled deep → list must not go blank
  • filter change resets scroll to top → visible rows change and remain valid

All 3 tests pass.

When a filter was applied while the user was scrolled deep, the
windowing useMemo computed startIndex from a stale scrollTop that
exceeded the new list's bounds, causing events.slice() to return
nothing and the list to go blank.

Fix: clamp scrollTop to maxScrollTop before computing startIndex so
the visible window is always within the filtered result's bounds.
@Abd-Standard
Abd-Standard merged commit d78f9b5 into Core-Foundry:main Jun 20, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Resolve Pagination Reset on Filter Change

2 participants