Skip to content

Commit 18e1c36

Browse files
fix(instantsearch): warn deprecated usage of searchParameters (#4151)
1 parent 90ad88c commit 18e1c36

File tree

3 files changed

+68
-7
lines changed

3 files changed

+68
-7
lines changed

.storybook/decorators.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ export const withHits = (
2828
const search = instantsearch({
2929
indexName,
3030
searchClient: algoliasearch(appId, apiKey),
31-
searchParameters: {
32-
hitsPerPage: 4,
33-
attributesToSnippet: ['description:15'],
34-
snippetEllipsisText: '[…]',
35-
...searchParameters,
36-
},
3731
routing: {
3832
router: {
3933
write: (routeState: object) => {
@@ -47,6 +41,15 @@ export const withHits = (
4741
...instantsearchOptions,
4842
});
4943

44+
search.addWidget(
45+
instantsearch.widgets.configure({
46+
hitsPerPage: 4,
47+
attributesToSnippet: ['description:15'],
48+
snippetEllipsisText: '[…]',
49+
...searchParameters,
50+
})
51+
);
52+
5053
const containerElement = document.createElement('div');
5154

5255
// Add the preview container to add the stories in

src/lib/InstantSearch.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import version from './version';
77
import createHelpers from './createHelpers';
88
import {
99
createDocumentationMessageGenerator,
10+
createDocumentationLink,
1011
findIndex,
1112
isPlainObject,
1213
mergeDeep,
1314
noop,
15+
warning,
1416
} from './utils';
1517

1618
const withUsage = createDocumentationMessageGenerator({
@@ -48,7 +50,7 @@ class InstantSearch extends EventEmitter {
4850
const {
4951
indexName = null,
5052
numberLocale,
51-
searchParameters = {},
53+
searchParameters,
5254
routing = null,
5355
searchFunction,
5456
stalledSearchDelay = 200,
@@ -88,6 +90,23 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend
8890
throw new Error('The provided `insightsClient` must be a function.');
8991
}
9092

93+
warning(
94+
!searchParameters,
95+
`The \`searchParameters\` option is deprecated and will not be supported in InstantSearch.js 4.x.
96+
97+
You can replace it with the \`configure\` widget:
98+
99+
\`\`\`
100+
search.addWidgets([
101+
configure(${JSON.stringify(searchParameters, null, 2)})
102+
]);
103+
\`\`\`
104+
105+
See ${createDocumentationLink({
106+
name: 'configure',
107+
})}`
108+
);
109+
91110
this.client = searchClient;
92111
this.insightsClient = insightsClient;
93112
this.helper = null;

src/lib/__tests__/InstantSearch-test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import algoliaSearchHelper from 'algoliasearch-helper';
22
import InstantSearch from '../InstantSearch';
33
import version from '../version';
4+
import { warning } from '../utils';
45

56
jest.mock('algoliasearch-helper', () => {
67
const module = require.requireActual('algoliasearch-helper');
@@ -217,6 +218,44 @@ describe('InstantSearch lifecycle', () => {
217218
expect(algoliaSearchHelper).not.toHaveBeenCalled();
218219
});
219220

221+
it('warns deprecated usage of `searchParameters`', () => {
222+
warning.cache = {};
223+
224+
expect(() => {
225+
// eslint-disable-next-line no-new
226+
new InstantSearch({
227+
indexName,
228+
searchClient: algoliasearch(appId, apiKey),
229+
searchParameters: {
230+
disjunctiveFacets: ['brand'],
231+
disjunctiveFacetsRefinements: {
232+
brand: ['Samsung'],
233+
},
234+
},
235+
});
236+
})
237+
.toWarnDev(`[InstantSearch.js]: The \`searchParameters\` option is deprecated and will not be supported in InstantSearch.js 4.x.
238+
239+
You can replace it with the \`configure\` widget:
240+
241+
\`\`\`
242+
search.addWidgets([
243+
configure({
244+
"disjunctiveFacets": [
245+
"brand"
246+
],
247+
"disjunctiveFacetsRefinements": {
248+
"brand": [
249+
"Samsung"
250+
]
251+
}
252+
})
253+
]);
254+
\`\`\`
255+
256+
See https://www.algolia.com/doc/api-reference/widgets/configure/js/`);
257+
});
258+
220259
it('does not fail when passing same references inside multiple searchParameters props', () => {
221260
const disjunctiveFacetsRefinements = { fruits: ['apple'] };
222261
const facetsRefinements = disjunctiveFacetsRefinements;

0 commit comments

Comments
 (0)