Skip to content

Commit

Permalink
fix(index): do not warn for nested index widget (#4620)
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroenv authored Jan 11, 2021
1 parent ac2444c commit 7502744
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/widgets/index/__tests__/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2810,5 +2810,29 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/index-widge
'[InstantSearch.js]: The `getWidgetState` method is renamed `getWidgetUiState` and will no longer exist under that name in InstantSearch.js 5.x. Please use `getWidgetUiState` instead.'
);
});

test('does not warn for index itself', () => {
warning.cache = {};

const instance = index({ indexName: 'indexName' });
const searchClient = createSearchClient();
const mainHelper = algoliasearchHelper(searchClient, '', {});
const instantSearchInstance = createInstantSearch({
mainHelper,
});

instance.addWidgets([index({ indexName: 'other' })]);

expect(() => {
instance.init(
createInitOptions({
instantSearchInstance,
parent: null,
})
);
}).not.toWarnDev(
'[InstantSearch.js]: The `getWidgetState` method is renamed `getWidgetUiState` and will no longer exist under that name in InstantSearch.js 5.x. Please use `getWidgetUiState` instead.'
);
});
});
});
4 changes: 3 additions & 1 deletion src/widgets/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,9 @@ const index = (props: IndexProps): Index => {

localWidgets.forEach(widget => {
warning(
!widget.getWidgetState,
// if it has NO getWidgetState or if it has getWidgetUiState, we don't warn
// aka we warn if there's _only_ getWidgetState
!widget.getWidgetState || Boolean(widget.getWidgetUiState),
'The `getWidgetState` method is renamed `getWidgetUiState` and will no longer exist under that name in InstantSearch.js 5.x. Please use `getWidgetUiState` instead.'
);

Expand Down

0 comments on commit 7502744

Please sign in to comment.