Skip to content

Commit f304b63

Browse files
feat(headless): restore range facet state after refresh (#4599)
[CAPI-1470](https://coveord.atlassian.net/browse/CAPI-1470) Barca is crashing on page refresh when a numerical range facet is used because headless isn't refresh the `facetSet` in the way it does for other facets. Test on barca and now works as expected. Before: https://github.com/user-attachments/assets/6bf6faed-87df-42c2-90a1-5ad5193eaaf3 Now: https://github.com/user-attachments/assets/55de9da9-9ad1-4bd3-b524-84a756342371 [CAPI-1470]: https://coveord.atlassian.net/browse/CAPI-1470?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 91a2538 commit f304b63

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

packages/headless/src/features/commerce/facets/facet-set/facet-set-reducers.ts

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export function restoreFromParameters(
2929
if (action.payload.nf) {
3030
restoreRangeFacets(state, action.payload.nf, 'numericalRange');
3131
}
32+
if (action.payload.mnf) {
33+
restoreRangeFacets(state, action.payload.mnf, 'numericalRange');
34+
}
3235
if (action.payload.df) {
3336
restoreRangeFacets(state, action.payload.df, 'dateRange');
3437
}

packages/headless/src/features/commerce/facets/facet-set/facet-set-slice.test.ts

+61
Original file line numberDiff line numberDiff line change
@@ -3024,6 +3024,67 @@ describe('commerceFacetSetReducer', () => {
30243024
);
30253025
});
30263026

3027+
it('populates manual numeric facet requests', () => {
3028+
const finalState = commerceFacetSetReducer(
3029+
state,
3030+
action({
3031+
mnf: {
3032+
manual_numeric_facet_1: [
3033+
{
3034+
start: 1,
3035+
end: 10,
3036+
endInclusive: false,
3037+
},
3038+
{
3039+
start: 15,
3040+
end: 20,
3041+
endInclusive: true,
3042+
},
3043+
],
3044+
manual_numeric_facet_2: [
3045+
{
3046+
start: 11,
3047+
end: 20,
3048+
endInclusive: true,
3049+
},
3050+
],
3051+
},
3052+
})
3053+
);
3054+
3055+
const firstRequest = finalState['manual_numeric_facet_1'].request;
3056+
expect(firstRequest.type).toEqual('numericalRange');
3057+
expect(firstRequest.values).toEqual(
3058+
expect.arrayContaining([
3059+
expect.objectContaining({
3060+
start: 1,
3061+
end: 10,
3062+
endInclusive: false,
3063+
state: 'selected',
3064+
}),
3065+
expect.objectContaining({
3066+
start: 15,
3067+
end: 20,
3068+
endInclusive: true,
3069+
state: 'selected',
3070+
}),
3071+
])
3072+
);
3073+
3074+
const secondRequest = finalState['manual_numeric_facet_2'].request;
3075+
expect(secondRequest.type).toEqual('numericalRange');
3076+
expect(secondRequest.values).toEqual(
3077+
expect.arrayContaining([
3078+
expect.objectContaining({
3079+
start: 11,
3080+
end: 20,
3081+
endInclusive: true,
3082+
state: 'selected',
3083+
}),
3084+
])
3085+
);
3086+
});
3087+
30273088
it('populates date facet requests', () => {
30283089
const finalState = commerceFacetSetReducer(
30293090
state,

0 commit comments

Comments
 (0)