Skip to content

Commit

Permalink
fix(infinite-hits): fix #2543 (#2948)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bobylito authored May 29, 2018
1 parent a5d7064 commit bbf9f8f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/widgets/infinite-hits/__tests__/infinite-hits-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,17 @@ describe('infiniteHits()', () => {
expect(ReactDOM.render.secondCall.args[1]).toEqual(container);
});

it('does not accept both item and allItems templates', () => {
expect(
infiniteHits.bind({ container, templates: { item: '', allItems: '' } })
it('does not accept allItems templates', () => {
expect(() =>
infiniteHits({ container, templates: { allItems: '' } })
).toThrow();

expect(() =>
infiniteHits({ container, templates: { allItems: 'not empty' } })
).toThrow();

expect(() =>
infiniteHits({ container, templates: { allItems: () => 'template' } })
).toThrow();
});

Expand Down
8 changes: 8 additions & 0 deletions src/widgets/infinite-hits/infinite-hits.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ export default function infiniteHits({
throw new Error(`Must provide a container.${usage}`);
}

// We have this specific check because unlike the hits, infiniteHits does not support this template.
// This can be misleading as they are very similar.
if (templates.allItems !== undefined) {
throw new Error(
'allItems is not a valid template for the infiniteHits widget'
);
}

const containerNode = getContainerNode(container);
const cssClasses = {
root: cx(bem(null), userCssClasses.root),
Expand Down

0 comments on commit bbf9f8f

Please sign in to comment.