Skip to content

fix: PLP "Load more products" overwriting list instead of appending - #3305

Merged
lemagnetic merged 2 commits into
3.xfrom
fix/plp-infinity-scroll-overiwriting
May 11, 2026
Merged

lemagnetic merged 2 commits into
3.xfrom
fix/plp-infinity-scroll-overiwriting

Conversation

@lemagnetic

@lemagnetic lemagnetic commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

On a PLP, clicking "Load more products" was supposed to append the next 12 products below the existing 12. Instead, the new page replaced the current list, so the user kept seeing only 12 items.

Root cause: the Provider in @faststore/sdk was resetting the infinite-scroll pages array on every URL change reaching <SearchProvider>. Two converging conditions made it fire on a Sentinel-triggered URL update:

  1. parseSearchState always returns a new selectedFacets array reference, even when the content is identical.
  2. The Sentinel reflects the page in viewport into the URL via router.replace('?page=N'). That update bubbles back to the Provider via asPath, and the effect's referential deps fire, calling resetInfiniteScroll(N), which collapses pages to [N].

How it works?

The useEffect in packages/sdk/src/search/Provider.tsx was split into two with different responsibilities:

  • setState(rest) keeps running on any change to term, sort, selectedFacets, or page — preserving the search-context sync introduced in fix: search update #3015.
  • resetInfiniteScroll now runs only when the content of the search (term / sort / selectedFacets) changes, gated by a stable, content-based key built via JSON.stringify. Page-only URL updates no longer trigger a reset.

rest.page is intentionally excluded from the reset effect's deps. React closures still capture the latest value at the moment the effect runs, so when content actually changes (e.g., the user toggles a filter, which atomically also sets page: 0), the reset uses the correct page. An eslint-disable with a code comment documents the intent.

How to test it?

Pre-conditions: any PLP with more than 12 products and "Load more products" enabled.

  • Open a PLP, confirm the first 12 products render.
  • Click Load more products , the next 12 products must be appended below the original 12 (24 in total). Repeat the click — 36, 48, and so on.
  • Toggle a filter while having multiple pages stacked, the gallery must reset to the first page of the new filtered results.
  • Change the Sort while having multiple pages stacked, same expected reset.
  • Reload the page on a deep-link such as /<plp>?page=2, the gallery should open directly on page 2 (deep-link still works).
  • Use the browser Back / Forward buttons after stacking pages, navigation works as usual.

Starters Deploy Preview

URL Preview with fix

References

  • Jira ticket: SFS-3162
  • fix: search update #3015 (fix: search update) — introduced the dependency-array on the Provider effect that, combined with the Sentinel, caused the regression.

Summary by CodeRabbit

  • Bug Fixes
    • More reliable infinite-scroll reset so results reload consistently when search term, sort order, or filters change.
  • Style
    • Improved product grid responsive spacing and bottom padding across mobile, tablet, notebook, and desktop breakpoints for more consistent layout and pagination spacing.

Review Change Stack

@lemagnetic
lemagnetic requested a review from a team as a code owner May 7, 2026 21:43
@lemagnetic lemagnetic added the bug Something isn't working label May 7, 2026
@lemagnetic
lemagnetic requested review from eduardoformiga and emersonlaurentino and removed request for a team May 7, 2026 21:43
@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Provider: infinite-scroll reset now depends on a memoized searchContentKey (from term, sort, selectedFacets) and shouldResetInfiniteScroll; pagination (page) no longer triggers resets. ProductGrid: responsive bottom padding tokens updated and an old pagination margin-top rule removed.

Changes

Search Content Stability

Layer / File(s) Summary
Hook imports
packages/sdk/src/search/Provider.tsx
useMemo is imported to enable memoization.
State push effect
packages/sdk/src/search/Provider.tsx
Effect that sets global search state depends on rest.term, rest.sort, rest.selectedFacets, and rest.page.
Search content key memoization
packages/sdk/src/search/Provider.tsx
New searchContentKey computed via useMemo, normalizing term, sort, and selectedFacets into a stable identifier (excludes page).
Infinite-scroll reset effect
packages/sdk/src/search/Provider.tsx
Reset effect now triggers resetInfiniteScroll(rest.page ?? 0) only when searchContentKey or shouldResetInfiniteScroll change; rest.page removed from dependencies.
Render output
packages/sdk/src/search/Provider.tsx
No functional change; children rendered unchanged.

ProductGrid Spacing

Layer / File(s) Summary
Tablet padding & pagination rule
packages/ui/src/components/organisms/ProductGrid/styles.scss
Adds padding-bottom: var(--fs-product-grid-gap-tablet) in >=tablet and removes previous &:nth-of-type(n + $pagination-start-index) margin-top pagination rule.
Mobile padding token
packages/ui/src/components/organisms/ProductGrid/styles.scss
For <notebook, bottom padding now uses --fs-product-grid-gap-mobile instead of --fs-grid-gap-2.
Notebook / Desktop padding
packages/ui/src/components/organisms/ProductGrid/styles.scss
For >=notebook, keeps desktop grid-gap and adds padding-bottom: var(--fs-product-grid-gap-desktop).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • eduardoformiga
  • lucasfp13

Poem

The Provider learned what truly defines the search,
A key from terms and facets, steady as a birch.
Pages glide on by, no needless reset wake,
While grids gain gentle bottoms for a smoother take. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main fix: resolving the regression where 'Load more products' was overwriting instead of appending to the product list.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/plp-infinity-scroll-overiwriting

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codesandbox-ci

codesandbox-ci Bot commented May 7, 2026 •

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@coderabbitai

coderabbitai Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

@eduardoformiga eduardoformiga left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've tested and it worked as expected.
We must replicate it to the v4.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ui/src/components/organisms/ProductGrid/styles.scss`:
- Line 34: The stylesheet uses the deprecated CSS property grid-gap in
ProductGrid styles (three occurrences) — replace each grid-gap declaration with
the modern gap property (e.g., change grid-gap:
var(--fs-product-grid-gap-desktop); to gap: var(--fs-product-grid-gap-desktop);)
and update the other responsive occurrences similarly so the grid/flex spacing
uses gap consistently; ensure no other grid-gap instances remain in the same
stylesheet.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cd395f1f-e82f-42a1-913e-dfd45824f87e

📥 Commits

Reviewing files that changed from the base of the PR and between 89b33ac and 650597f.

📒 Files selected for processing (1)
  • packages/ui/src/components/organisms/ProductGrid/styles.scss

}

@include media(">=notebook") {
grid-gap: var(--fs-product-grid-gap-desktop);

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify deprecated property usage in SCSS
rg -n '\bgrid-gap\s*:' --type=scss

# Optional lint check for this file
pnpm stylelint packages/ui/src/components/organisms/ProductGrid/styles.scss

Repository: vtex/faststore

Length of output: 50654


Replace deprecated grid-gap with gap in responsive styles.

Stylelint flags grid-gap as deprecated at lines 21, 25, and 34. Use the modern gap property for Grid/Flex spacing instead.

Suggested diff
-  grid-gap: var(--fs-product-grid-gap-mobile);
+  gap: var(--fs-product-grid-gap-mobile);

   `@include` media(">=tablet") {
     grid-template-columns: repeat(var(--fs-product-grid-columns-desktop), 1fr);
-    grid-gap: var(--fs-product-grid-gap-tablet);
+    gap: var(--fs-product-grid-gap-tablet);
     padding-bottom: var(--fs-product-grid-gap-tablet);
   }

   `@include` media(">=notebook") {
-    grid-gap: var(--fs-product-grid-gap-desktop);
+    gap: var(--fs-product-grid-gap-desktop);
     padding-bottom: var(--fs-product-grid-gap-desktop);
   }
🧰 Tools
🪛 Stylelint (17.11.0)

[error] 34-34: Expected "grid-gap" to be "gap" (property-no-deprecated)

(property-no-deprecated)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/components/organisms/ProductGrid/styles.scss` at line 34, The
stylesheet uses the deprecated CSS property grid-gap in ProductGrid styles
(three occurrences) — replace each grid-gap declaration with the modern gap
property (e.g., change grid-gap: var(--fs-product-grid-gap-desktop); to gap:
var(--fs-product-grid-gap-desktop);) and update the other responsive occurrences
similarly so the grid/flex spacing uses gap consistently; ensure no other
grid-gap instances remain in the same stylesheet.

@pkg-pr-new

pkg-pr-new Bot commented May 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

@faststore/api

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/cli

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/components

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/core

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/graphql-utils

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/lighthouse

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/sdk

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/ui

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

commit: 650597f

@lemagnetic
lemagnetic merged commit b6a98bf into 3.x May 11, 2026
5 checks passed
@lemagnetic
lemagnetic deleted the fix/plp-infinity-scroll-overiwriting branch May 11, 2026 16:26
@coderabbitai coderabbitai Bot mentioned this pull request May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants