Skip to content

Commit bbf9f8f

Browse files
authored
fix(infinite-hits): fix #2543 (#2948)
The infinite hits widget is based internally on the hits widget which accepts the allItems template. However this template is not usable for the purpose of the infinite hits widget. In order to prevent users from using this buggy and yet accepted option this PR generates a exception if we detect this particular template. Fix #2543
1 parent a5d7064 commit bbf9f8f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/widgets/infinite-hits/__tests__/infinite-hits-test.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,17 @@ describe('infiniteHits()', () => {
7676
expect(ReactDOM.render.secondCall.args[1]).toEqual(container);
7777
});
7878

79-
it('does not accept both item and allItems templates', () => {
80-
expect(
81-
infiniteHits.bind({ container, templates: { item: '', allItems: '' } })
79+
it('does not accept allItems templates', () => {
80+
expect(() =>
81+
infiniteHits({ container, templates: { allItems: '' } })
82+
).toThrow();
83+
84+
expect(() =>
85+
infiniteHits({ container, templates: { allItems: 'not empty' } })
86+
).toThrow();
87+
88+
expect(() =>
89+
infiniteHits({ container, templates: { allItems: () => 'template' } })
8290
).toThrow();
8391
});
8492

src/widgets/infinite-hits/infinite-hits.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ export default function infiniteHits({
124124
throw new Error(`Must provide a container.${usage}`);
125125
}
126126

127+
// We have this specific check because unlike the hits, infiniteHits does not support this template.
128+
// This can be misleading as they are very similar.
129+
if (templates.allItems !== undefined) {
130+
throw new Error(
131+
'allItems is not a valid template for the infiniteHits widget'
132+
);
133+
}
134+
127135
const containerNode = getContainerNode(container);
128136
const cssClasses = {
129137
root: cx(bem(null), userCssClasses.root),

0 commit comments

Comments
 (0)