Repository navigation
fix: search update - #3015
Merged
Merged
fix: search update#3015
Conversation
|
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. |
lariciamota
marked this pull request as ready for review
September 5, 2025 13:05
lariciamota
requested review from
lucasfp13 and
renatamottam
and removed request for
a team
September 5, 2025 13:05
lucasfp13
approved these changes
Sep 8, 2025
lemagnetic
added a commit
that referenced
this pull request
May 11, 2026
…3305) ## 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 #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](https://sfj-4f851a9--storeframework.preview.vtex.app/office?category-1=office&fuzzy=0&operator=and&facets=category-1%2Cfuzzy%2Coperator&sort=score_desc&page=1) <!-- TODO: add deploy preview URL once available --> ## References - Jira ticket: [SFS-3162](https://vtex-dev.atlassian.net/browse/SFS-3162) - #3015 (`fix: search update`) — introduced the dependency-array on the `Provider` effect that, combined with the `Sentinel`, caused the regression. [SFS-3162]: https://vtex-dev.atlassian.net/browse/SFS-3162?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. [](https://app.coderabbit.ai/change-stack/vtex/faststore/pull/3305) <!-- end of auto-generated comment: release notes by coderabbit.ai -->
lemagnetic
added a commit
that referenced
this pull request
May 11, 2026
…3308) ## 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 #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](https://sfj-4f851a9--storeframework.preview.vtex.app/office?category-1=office&fuzzy=0&operator=and&facets=category-1%2Cfuzzy%2Coperator&sort=score_desc&page=1) <!-- TODO: add deploy preview URL once available --> ## References - Jira ticket: [SFS-3162](https://vtex-dev.atlassian.net/browse/SFS-3162) - #3015 (`fix: search update`) — introduced the dependency-array on the `Provider` effect that, combined with the `Sentinel`, caused the regression. [SFS-3162]: https://vtex-dev.atlassian.net/browse/SFS-3162?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. [](https://app.coderabbit.ai/change-stack/vtex/faststore/pull/3305) <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's the purpose of this pull request?
The search context wasn't being updated properly.
(And the
ProductTileswasn't considering the global pickup point - I took the opportunity to fix it also)How it works?
I've reverted the previous fix, which was fixing a part of the issue, so we could find a solution to fix the whole issue. And I found that since the Search Provider had a useEffect with an empty dependency array, it was causing the search to not be updated properly.
How to test it?
You can test searching and navigating through PLPs. You can select facets, and make a new search for example.
An example of issue (account
vendemo):women's microdot pinkSizewomen's microdot nightClothes SizeAfter the fix the selected facets should be reseted when making a new search, the URL should contain fuzzy values and should not go back to previous search params.
Starters Deploy Preview
https://github.com/dp-faststore-org/vendemo-dp/pull/84 / https://github.com/vtex-sites/faststoreqa.store/pull/863
Before the fix:
vendemo) - https://vendemo-cm9sir9v900u7z6llkl62l70j-c0yp9zvaf.b.vtex.app/storeframework) - https://storeframework-cm652ufll028lmgv665a6xv0g-ht2gb8snr.b.vtex.app/After the fix:
vendemo) - https://vendemo-cm9sir9v900u7z6llkl62l70j-tcm1nzpoi.b.vtex.app/storeframework) - https://storeframework-cm652ufll028lmgv665a6xv0g-mto9dm1vc.b.vtex.app/References