Skip to content

Commit

Permalink
fix(headless): undefined error when query suggestions adds a new face…
Browse files Browse the repository at this point in the history
…t without values (#4257)

https://coveord.atlassian.net/browse/KIT-3457

The steps for the bug to happen are here below. This bug only happens
very rarely with a config. The config used for the commerce ssr sample
happened to trigger it.

1. Facets are or are not in the state
2. `fetchQuerySuggestions.fulfilled` adds new facets without a proper
‘request.values’ attribute
([here](https://github.com/coveo/ui-kit/blob/87ef80c648225ce21b002282060958cef9556fc8/packages/headless/src/features/commerce/facets/facet-set/facet-set-slice.ts#L488))
3. On a new search with ‘clearFilter’ we call `clearAllCoreFacets`, that
action then tries a forEach on every request on every values
([here](https://github.com/coveo/ui-kit/blob/5730c4afa8eedca06ef4f83c019465d9264166c2/packages/headless/src/features/commerce/facets/facet-set/facet-set-slice.ts#L492))
4. Crash

Steps to reproduce:
1. checkout KIT-3457
2. Remove the line added here in the PR
3. npm run dev -w @coveo/headless-ssr-commerce-samples
5. query 'sd'
6. press 'Search'
7. add 's' to the query
8. press 'Search'

---------

Co-authored-by: ylakhdar <ylakhdar@coveo.com>
Co-authored-by: Frederic Beaudoin <fbeaudoin@coveo.com>
Co-authored-by: Nico Labarre <Spuffynism@users.noreply.github.com>
  • Loading branch information
4 people committed Aug 22, 2024
1 parent 7f4fcfe commit 8b5dd42
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -692,12 +692,14 @@ describe('commerceFacetSetReducer', () => {
[getFacetIdWithCommerceFieldSuggestionNamespace('regular_field')]: {
request: {
initialNumberOfValues: 10,
values: [],
},
},
[getFacetIdWithCommerceFieldSuggestionNamespace('hierarchical_field')]:
{
request: {
initialNumberOfValues: 10,
values: [],
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ function handleFieldSuggestionsFulfilled(
state[facetId] = {request: {} as AnyFacetRequest};
facetRequest = state[facetId].request;
facetRequest.initialNumberOfValues = 10;
facetRequest.values = [];
}
}

Expand Down

0 comments on commit 8b5dd42

Please sign in to comment.