Skip to content

fix: search update - #3015

Merged
lariciamota merged 4 commits into
mainfrom
fix/search-update
Sep 9, 2025
Merged

lariciamota merged 4 commits into
mainfrom
fix/search-update

Conversation

@lariciamota

@lariciamota lariciamota commented Sep 4, 2025 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

The search context wasn't being updated properly.
(And the ProductTiles wasn'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):

  1. Search for women's microdot pink
  2. Select size L in the facet Size
  3. Search for women's microdot night
  4. Before the fix: the size facet selected in the previous search is still selected
  5. Before the fix: the URL isn't updated with the fuzzy values
  6. Select size M in the facet Clothes Size
  7. Before the fix: the search term in the URL search params go back to the previous search ("pink")
  8. Before the fix: if you refresh the page the search results go back to the previous search ("pink")

After 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

References

@lariciamota lariciamota self-assigned this Sep 4, 2025
@lariciamota lariciamota added the bug Something isn't working label Sep 4, 2025
@codesandbox-ci

codesandbox-ci Bot commented Sep 4, 2025 •

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.

@lariciamota
lariciamota marked this pull request as ready for review September 5, 2025 13:05
@lariciamota
lariciamota requested a review from a team as a code owner September 5, 2025 13:05
@lariciamota
lariciamota requested review from lucasfp13 and renatamottam and removed request for a team September 5, 2025 13:05
@lariciamota
lariciamota merged commit 74d3261 into main Sep 9, 2025
@lariciamota
lariciamota deleted the fix/search-update branch September 9, 2025 14:11
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.

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](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.

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/vtex/faststore/pull/3305)
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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