Repository navigation
[NO JIRA][withInfiniteScroll] Fix reset uses initiallyLoadedElements instead of elementsPerScroll - #4689
Conversation
…lementsPerScroll When the data source changes (either via `updateData` or a new `dataSource` prop), the component resets to index 0. Both reset paths were using `elementsPerScroll` for the reload fetch, which produces the wrong page size when `initiallyLoadedElements !== elementsPerScroll`. A reset returns the list to its initial state, so it should behave identically to `componentDidMount`, which already correctly uses `initiallyLoadedElements`. When both props are equal (the default of 5/5) this change is a no-op. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4689 to see this build running in a browser. |
…lyLoadedElements" test
|
|
||
| await screen.findByText('Element 10'); | ||
| expect(await screen.queryByText('Element 11')).not.toBeInTheDocument(); | ||
| await act(() => intersect()); // fetchItems(11, 12) |
There was a problem hiding this comment.
Wrapping with act() here to avoid the state changed warning.
This could also be included directly in the intersect() declaration in the test suite setup, but then all snapshots fail - so maybe that would be for a follow up code maintenance task.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes withInfiniteScroll reset behavior so that resets load initiallyLoadedElements (matching initial mount) rather than elementsPerScroll, and adds regression tests for both reset paths.
Changes:
- Update
componentDidUpdatereset to requestinitiallyLoadedElements. - Update
updateDatareset logic to useinitiallyLoadedElementsfor “first load” behavior. - Add tests covering
updateDatareset,dataSourceprop change reset, and a “refetch all visible” scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/backpack-web/src/bpk-component-infinite-scroll/src/withInfiniteScroll.js | Align reset fetch size with initial mount by using initiallyLoadedElements. |
| packages/backpack-web/src/bpk-component-infinite-scroll/src/withInfiniteScroll-test.js | Add regression tests for both reset paths and a visible-elements refetch case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Visit https://backpack.github.io/storybook-prs/4689 to see this build running in a browser. |
- BpkDatepicker.tsx: keep HEAD (defaultProps removal, optional prop) - withInfiniteScroll.js: take main (initiallyLoadedElements bug fix #4689) - BpkProvider.tsx: take main (activeCache/hasExternalCache, drop undefined isNested/parentCache refs) Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
Summary
withInfiniteScrollhas two props for page size:initiallyLoadedElements— items loaded on first mountelementsPerScroll— items added on each subsequent scrollThese are intentionally different for some callers. When a reset to index 0 is triggered — either because
dataSourcechanges orupdateDatafires — both reset paths were usingelementsPerScrollinstead ofinitiallyLoadedElements. A reset returns the list to its initial state and should behave identically tocomponentDidMount, which already correctly usesinitiallyLoadedElements.The two affected paths:
1.
updateData— called when the data source contents change (e.g. a filter pill switch):2.
componentDidUpdate— called when thedataSourceprop reference changes:When both props are equal (the Backpack default of
5/5) this change is a no-op.Red-Green TDD
Two failing tests were written first, each targeting one of the broken paths:
Both tests use
initiallyLoadedElements=11, elementsPerScroll=12— the exact values from the real-world caller. The fix made both green without touching any existing snapshot or test.Validated in web-platform
The fix was tested locally by building
backpack-weband symlinking the dist into web-platform via apnpm link:override, then running the consumer's integration test:This test renders the full
ResultListcomponent withinitiallyLoadedElements=11, elementsPerScroll=12, switches a filter pill (triggering adataSourceprop change), and asserts that the reset produces exactly 11 cards — not 12.Blast radius — all Skyscanner repos
Searched the entire Skyscanner org for usages of
initiallyLoadedElementsalongsidewithInfiniteScroll.initiallyLoadedElementselementsPerScrollcombined-exploreResultList11(advert in first slot) or126(after advert loaded) or12flights-day-viewInfiniteScrollResults0(intentional — nothing on mount)sharedInfiniteScrollResultsList(passthrough wrapper)InfiniteCarGroupListresultsToShow.length(dynamic, starts at15)15(FETCH_RESPONSE_POLICY.INITIAL_RESULTS_PER_PAGE)resultsToShow.lengthcan differ from15during polling; reset would previously reload15, now reloads the actual current lengthInfiniteHotelCardsListinitialHotels.length(dynamic)batchCount(config-driven)InfiniteScrollReviewsreviews.length(dynamic)REVIEWS_PER_PAGE_MOBILEMediaWallELEMENTS_PER_SCROLLELEMENTS_PER_SCROLLResultsList1010DataAndErrors,CarsDataTable,HotelsDateTable205)initiallyLoadedElements=20overrides the default butelementsPerScrollstays at default5; reset now correctly reloads 20 items instead of the wrong 5Summary: The three "potentially yes" patterns (carhire, hotels, partner-portal) were all being reset with the wrong page size before this fix. The change makes reset consistent with initial mount in all cases. For any caller where both props happen to be equal at reset time the behaviour is identical.