Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: don't allow index widget when in composition mode #6459

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/instantsearch.js/src/lib/InstantSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,14 @@ See documentation: ${createDocumentationLink({
);
}

if (this.compositionID && widgets.some(isIndexWidget)) {
throw new Error(
withUsage(
'The `index` widget cannot be used with a composition-based InstantSearch implementation.'
)
);
}

this.mainIndex.addWidgets(widgets);

return this;
Expand Down
25 changes: 25 additions & 0 deletions packages/instantsearch.js/src/lib/__tests__/InstantSearch-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,31 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend
'[InstantSearch.js]: No indexName provided, nor an explicit index widget in the widgets tree. This is required to be able to display results.'
);
});

it('throws if compositionID & index widget is provided', () => {
expect(() => {
const search = new InstantSearch({
searchClient: createSearchClient(),
compositionID: 'my-composition',
});

search.addWidgets([index({ indexName: 'indexName' })]);
}).toThrowErrorMatchingInlineSnapshot(`
"The \`index\` widget cannot be used with a composition-based InstantSearch implementation.

See documentation: https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/"
`);
});

it('does not throw if compositionID is not provided while index widget is provided', () => {
expect(() => {
const search = new InstantSearch({
searchClient: createSearchClient(),
});

search.addWidgets([index({ indexName: 'indexName' })]);
}).not.toThrow();
});
});

it('throws if insightsClient is not a function', () => {
Expand Down
Loading