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

[IRN-6854] Fix card-list rail pagination on short final page - #4975

Merged
Ezreal Yang (Supremeyh) merged 4 commits into
mainfrom
IRN-6854/card-list-rail-short-final-page-pagination
Aug 3, 2026
Merged

Ezreal Yang (Supremeyh) merged 4 commits into
mainfrom
IRN-6854/card-list-rail-short-final-page-pagination

Conversation

@jimmycook

Copy link
Copy Markdown
Contributor

Summary

Fixes a pagination bug in BpkCardList row/rail mode.

Problem

When the final page of a rail holds fewer cards than initiallyShownCards (odd totals — e.g. 3 cards shown 2-wide), physically scrolling to the end does not advance the pagination indicator.

Cause: in usePageScrollSync, the page index is derived from Math.floor(firstVisibleIndex / initiallyShownCards). On a short final page there isn't enough content to scroll that page's first card to the viewport start, so firstVisibleIndex never reaches it and the indicator stays on the previous page.

Change

  • BpkCardListRowRail/utils.tsx — in usePageScrollSync, treat a visible last card as the final page; otherwise the existing calculation is used.
  • BpkCardListRowRail/utils-test.tsx — unit test for the short-final-page case.
  • BpkCardList.stories.tsx — two repro stories:
    • RowToRailShortFinalPage (2-wide, 3 cards)
    • RowToRailShortFinalPageWider (4-wide, 10 cards)

How to review

Storybook → bpk-component-card-list → the two RowToRailShortFinalPage* stories. On desktop, physically scroll to the last card; the indicator now tracks to the final page. pnpm jest packages/backpack-web/src/bpk-component-card-list is green (61 tests).

Notes

Draft — no changelog entry yet, wanted a sanity check on the approach before polishing.

🤖 Generated with Claude Code

Jimmy cook (jimmycook) and others added 2 commits July 27, 2026 01:37
When a row/rail's final page holds fewer cards than initiallyShownCards
(odd totals, e.g. 3 cards shown 2-wide), physical scrolling to the end
never advanced the pagination indicator: firstVisibleIndex could not reach
the last page's start card, so Math.floor(firstVisibleIndex / shown) stayed
on the previous page.

Fix: in usePageScrollSync, if the last card is visible we've reached the
end, so snap the indicator to the final page.

Adds two Storybook repro stories (2-wide/3-card and 4-wide/10-card) and a
unit test for the short-final-page case.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

skyscanner-backpack-bot Bot commented Jul 28, 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 301f416

@jimmycook
Jimmy cook (jimmycook) marked this pull request as ready for review July 29, 2026 12:08
Copilot AI review requested due to automatic review settings July 29, 2026 12:08
@jimmycook Jimmy cook (jimmycook) added the patch Patch production bug label Jul 29, 2026
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

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 couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Fixes a pagination indicator bug in BpkCardList row/rail mode when the final page contains fewer cards than initiallyShownCards, preventing the indicator from advancing on physical scroll to the end.

Changes:

  • Update usePageScrollSync to treat “last card visible” as being on the final page.
  • Add a unit test covering the short-final-page scroll case.
  • Add Storybook repro stories for narrow and wider short-final-page scenarios.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/backpack-web/src/bpk-component-card-list/src/BpkCardListRowRail/utils.tsx Adjusts page index derivation to handle short final pages.
packages/backpack-web/src/bpk-component-card-list/src/BpkCardListRowRail/utils-test.tsx Adds regression test for the “short final page can’t align first card” behavior.
packages/backpack-web/src/bpk-component-card-list/src/BpkCardList.stories.tsx Adds Storybook stories to reproduce and verify the fix manually.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +212 to +218
// A short final page can't scroll its first card to the viewport start, so
// firstVisibleIndex stays on the previous page. Treat a visible last card as
// the final page.
const newPageIndex =
visibilityList[visibilityList.length - 1] === 1
? Math.ceil(visibilityList.length / initiallyShownCards) - 1
: Math.floor(firstVisibleIndex / initiallyShownCards);
expect(mockSetCurrentIndex).not.toHaveBeenCalled();
});

it('should snap to the last page when the final (short) page cannot scroll its first card to the start', () => {
Comment on lines +215 to +218
const newPageIndex =
visibilityList[visibilityList.length - 1] === 1
? Math.ceil(visibilityList.length / initiallyShownCards) - 1
: Math.floor(firstVisibleIndex / initiallyShownCards);

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.

This fires unconditionally whenever the last card is in the viewport and isUserScrollingRef.current is true. On a wide viewport that fits all cards simultaneously, any wheel or touchstart event sets isUserScrollingRef.current = true, then visibilityList[last] === 1 immediately triggers the override — forcing the indicator to the last page even though the user has never scrolled the rail.

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.

Last page guard added

Comment on lines 586 to +587

it('should snap to the last page when the final (short) page cannot scroll its first card to the start', () => {

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.

The added test (utils-test.tsx line 584) covers only the intended happy path (short final page, user scrolled to end → indicator advances). There is no test asserting the indicator does not jump when all cards are visible but the user has not scrolled the rail to the end.

Without a negative test, the false positive scenario in Issue 1 has no regression guard. Once the logic is tightened (per Issue 1), a negative test locks in the correct boundary and prevents future regressions.

Suggested addition (after fixing Issue 1):

it('should NOT snap to the last page when all cards are visible in a wide viewport', () => {
  // 4 cards, 2 shown per page, wide viewport: all visible from the start.
  // A wheel event should not force the indicator to page 1.
  const allVisibleList = [1, 1, 1, 1];
  // ... render hook with currentIndex: 0, initiallyShownCards: 2
  act(() => { mockContainer.dispatchEvent(new Event('wheel')); });
  rerender({ visibilityList: allVisibleList });
  expect(mockSetCurrentIndex).not.toHaveBeenCalled();
});

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.

test case added

Only treat a visible last card as the final page when the final page is
genuinely short (card count not divisible by initiallyShownCards). This
prevents falsely snapping the indicator when all cards fit in a wide viewport.

Adds a negative regression test to lock in the correct boundary.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

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.

lgtm

Comment on lines +215 to +218
const newPageIndex =
visibilityList[visibilityList.length - 1] === 1
? Math.ceil(visibilityList.length / initiallyShownCards) - 1
: Math.floor(firstVisibleIndex / initiallyShownCards);

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.

Last page guard added

@Supremeyh
Ezreal Yang (Supremeyh) merged commit c39a64a into main Aug 3, 2026
15 checks passed
@Supremeyh
Ezreal Yang (Supremeyh) deleted the IRN-6854/card-list-rail-short-final-page-pagination branch August 3, 2026 09:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

patch Patch production bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants