Skip to content
This repository was archived by the owner on Aug 5, 2026. It is now read-only.

[NO JIRA][withInfiniteScroll] Fix reset uses initiallyLoadedElements instead of elementsPerScroll - #4689

Merged
Ezreal Yang (Supremeyh) merged 4 commits into
mainfrom
fix/infinite-scroll-reset-uses-initially-loaded-elements
Jun 22, 2026
Merged

Ezreal Yang (Supremeyh) merged 4 commits into
mainfrom
fix/infinite-scroll-reset-uses-initially-loaded-elements

Conversation

@bjoern-wahle

@bjoern-wahle Björn Wahle (bjoern-wahle) commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

withInfiniteScroll has two props for page size:

  • initiallyLoadedElements — items loaded on first mount
  • elementsPerScroll — items added on each subsequent scroll

These are intentionally different for some callers. When a reset to index 0 is triggered — either because dataSource changes or updateData fires — both reset paths were using elementsPerScroll instead of initiallyLoadedElements. A reset returns the list to its initial state and should behave identically to componentDidMount, which already correctly uses initiallyLoadedElements.

The two affected paths:

1. updateData — called when the data source contents change (e.g. a filter pill switch):

// Before
const isFirstLoad = index < this.props.elementsPerScroll;
fetchItems({ elementsPerScroll: isFirstLoad ? this.props.elementsPerScroll : index })
// After
const isFirstLoad = index < this.props.initiallyLoadedElements;
fetchItems({ elementsPerScroll: isFirstLoad ? this.props.initiallyLoadedElements : index })

2. componentDidUpdate — called when the dataSource prop reference changes:

// Before
fetchItems({ index: 0, elementsPerScroll: this.props.elementsPerScroll })
// After
fetchItems({ index: 0, elementsPerScroll: this.props.initiallyLoadedElements })

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:

✗ updateData reset should use initiallyLoadedElements, not elementsPerScroll
  Expected: fetchItems called with (0, 11)
  Received: fetchItems called with (0, 12)  ← was using elementsPerScroll

✗ dataSource prop change should use initiallyLoadedElements, not elementsPerScroll
  Expected: fetchItems called with (0, 11)
  Received: fetchItems called with (0, 12)  ← same

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-web and symlinking the dist into web-platform via a pnpm link: override, then running the consumer's integration test:

✓ re-renders 11 cards (not 12) when the data source is refreshed after the initial load

This test renders the full ResultList component with initiallyLoadedElements=11, elementsPerScroll=12, switches a filter pill (triggering a dataSource prop 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 initiallyLoadedElements alongside withInfiniteScroll.

Repo Caller initiallyLoadedElements elementsPerScroll Affected?
web-platform combined-explore ResultList 11 (advert in first slot) or 12 6 (after advert loaded) or 12 Yes — diverge when advert is in first position
web-platform flights-day-view InfiniteScrollResults 0 (intentional — nothing on mount) config-service value No — reset fetches 0 items in both old and new code
web-platform shared InfiniteScrollResultsList (passthrough wrapper) caller-supplied caller-supplied Depends on caller — no direct divergence
carhire-homepage InfiniteCarGroupList resultsToShow.length (dynamic, starts at 15) 15 (FETCH_RESPONSE_POLICY.INITIAL_RESULTS_PER_PAGE) Potentially yes — resultsToShow.length can differ from 15 during polling; reset would previously reload 15, now reloads the actual current length
hotels-website InfiniteHotelCardsList initialHotels.length (dynamic) batchCount (config-driven) Potentially yes — same pattern as carhire; dynamic initial length vs fixed batch count
hotels-website InfiniteScrollReviews reviews.length (dynamic) REVIEWS_PER_PAGE_MOBILE Potentially yes — same pattern
hotels-website MediaWall ELEMENTS_PER_SCROLL ELEMENTS_PER_SCROLL No — both use the same constant
packages-website ResultsList 10 10 No — both equal
partner-portal DataAndErrors, CarsDataTable, HotelsDateTable 20 not set (default 5) Potentially yes — initiallyLoadedElements=20 overrides the default but elementsPerScroll stays at default 5; reset now correctly reloads 20 items instead of the wrong 5

Summary: 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.

…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]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

skyscanner-backpack-bot Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor
Warnings
⚠️

Package source files (e.g. packages/package-name/src/Component.js) were updated, but snapshots weren't. Have you checked that the tests still pass?

Browser support

If this is a visual change, make sure you've tested it in multiple browsers.

Generated by 🚫 dangerJS against 1328879

@bjoern-wahle
Björn Wahle (bjoern-wahle) marked this pull request as ready for review June 17, 2026 15:32
Copilot AI review requested due to automatic review settings June 17, 2026 15:32

await screen.findByText('Element 10');
expect(await screen.queryByText('Element 11')).not.toBeInTheDocument();
await act(() => intersect()); // fetchItems(11, 12)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 componentDidUpdate reset to request initiallyLoadedElements.
  • Update updateData reset logic to use initiallyLoadedElements for “first load” behavior.
  • Add tests covering updateData reset, dataSource prop 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.

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@Supremeyh Ezreal Yang (Supremeyh) changed the title fix(infinite-scroll): reset uses initiallyLoadedElements instead of elementsPerScroll [NO JIRA][withInfiniteScroll] Fix reset uses initiallyLoadedElements instead of elementsPerScroll Jun 22, 2026
@Supremeyh
Ezreal Yang (Supremeyh) merged commit e615ccd into main Jun 22, 2026
15 checks passed
@Supremeyh
Ezreal Yang (Supremeyh) deleted the fix/infinite-scroll-reset-uses-initially-loaded-elements branch June 22, 2026 02:28
IrinaWei added a commit that referenced this pull request Jun 23, 2026
- 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]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ai: claude patch Patch production bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants