diff --git a/packages/instantsearch-core/src/types/widget.ts b/packages/instantsearch-core/src/types/widget.ts index 5791e70ee7..131de32bae 100644 --- a/packages/instantsearch-core/src/types/widget.ts +++ b/packages/instantsearch-core/src/types/widget.ts @@ -246,17 +246,6 @@ type RequiredUiStateLifeCycle = { } ) => Partial; - /** - * This function is required for a widget to be taken in account for routing. - * It will derive a uiState for this widget based on the existing uiState and - * the search parameters applied. - * - * @deprecated Use `getWidgetUiState` instead. - * @param uiState - Current state. - * @param widgetStateOptions - Extra information to calculate uiState. - */ - getWidgetState?: RequiredUiStateLifeCycle['getWidgetUiState']; - /** * This function is required for a widget to behave correctly when a URL is * loaded via e.g. Routing. It receives the current UiState and applied search @@ -330,7 +319,7 @@ export type Widget< export type IndexWidget = Omit< Widget, - 'getWidgetUiState' | 'getWidgetState' + 'getWidgetUiState' > & { // public API addWidgets: (widgets: Array) => IndexWidget; @@ -371,10 +360,6 @@ export type IndexWidget = Omit< init: (options: IndexInitOptions) => void; render: (options: IndexRenderOptions) => void; dispose: (options?: DisposeOptions) => void; - /** - * @deprecated - */ - getWidgetState: (uiState: UiState) => UiState; getWidgetUiState: ( uiState: TSpecificUiState ) => TSpecificUiState; diff --git a/packages/instantsearch-core/src/widgets/__tests__/index-widget.test.ts b/packages/instantsearch-core/src/widgets/__tests__/index-widget.test.ts index 228a9db564..48ea187006 100644 --- a/packages/instantsearch-core/src/widgets/__tests__/index-widget.test.ts +++ b/packages/instantsearch-core/src/widgets/__tests__/index-widget.test.ts @@ -29,7 +29,6 @@ import { createIndexInitOptions, createDisposeOptions, } from '../../../test/createWidget'; -import { warnCache } from '../../lib/public'; import type { Widget } from '../../types'; import type { PlainSearchParameters } from 'algoliasearch-helper'; @@ -3231,94 +3230,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/index-widge }); }); - describe('getWidgetState', () => { - test('warns when index has this method', () => { - warnCache.current = {}; - - const instance = index({ indexName: 'indexName' }); - - expect(() => { - instance.getWidgetState({}); - }).toWarnDev( - '[InstantSearch]: The `getWidgetState` method is renamed `getWidgetUiState` and will no longer exist under that name in InstantSearch.js 5.x. Please use `getWidgetUiState` instead.' - ); - }); - - test('warns when widget has this method', () => { - warnCache.current = {}; - - const createDeprecatedSearchBox = (args: Partial = {}): Widget => - createWidget({ - dispose: jest.fn(({ state }) => { - return state.setQueryParameter('query', undefined); - }), - getWidgetState: jest.fn((uiState, { searchParameters }) => { - if (!searchParameters.query) { - return uiState; - } - - return { - ...uiState, - query: searchParameters.query, - }; - }), - getWidgetSearchParameters: jest.fn( - (searchParameters, { uiState }) => { - return searchParameters.setQueryParameter( - 'query', - uiState.query || '' - ); - } - ), - ...args, - }); - - const instance = index({ indexName: 'indexName' }); - const searchClient = createSearchClient(); - const mainHelper = algoliasearchHelper(searchClient, '', {}); - const instantSearchInstance = createInstantSearch({ - mainHelper, - }); - - instance.addWidgets([createDeprecatedSearchBox()]); - - expect(() => { - instance.init( - createIndexInitOptions({ - instantSearchInstance, - parent: null, - }) - ); - }).toWarnDev( - '[InstantSearch]: 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', () => { - warnCache.current = {}; - - const instance = index({ indexName: 'indexName' }); - const searchClient = createSearchClient(); - const mainHelper = algoliasearchHelper(searchClient, '', {}); - const instantSearchInstance = createInstantSearch({ - mainHelper, - }); - - instance.addWidgets([index({ indexName: 'other' })]); - - expect(() => { - instance.init( - createIndexInitOptions({ - instantSearchInstance, - parent: null, - }) - ); - }).not.toWarnDev( - '[InstantSearch]: The `getWidgetState` method is renamed `getWidgetUiState` and will no longer exist under that name in InstantSearch.js 5.x. Please use `getWidgetUiState` instead.' - ); - }); - }); - describe('setIndexUiState', () => { it('updates main UI state with an object', () => { const instance = index({ indexName: 'indexName' }); diff --git a/packages/instantsearch-core/src/widgets/index-widget.ts b/packages/instantsearch-core/src/widgets/index-widget.ts index bcabd94be5..6251e44086 100644 --- a/packages/instantsearch-core/src/widgets/index-widget.ts +++ b/packages/instantsearch-core/src/widgets/index-widget.ts @@ -3,7 +3,6 @@ import algoliasearchHelper from 'algoliasearch-helper'; import { addWidgetId, createDocumentationMessageGenerator, - warning, isIndexWidget, createInitArgs, createRenderArgs, @@ -120,15 +119,11 @@ function getLocalWidgetsUiState( return uiState; } - if (!widget.getWidgetUiState && !widget.getWidgetState) { - return uiState; - } - if (widget.getWidgetUiState) { return widget.getWidgetUiState(uiState, widgetStateOptions); } - return widget.getWidgetState!(uiState, widgetStateOptions); + return uiState; }, initialUiState); } @@ -685,13 +680,6 @@ export const index = (widgetParams: IndexWidgetParams): IndexWidget => { }); localWidgets.forEach((widget) => { - warning( - // 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.' - ); - if (widget.init) { widget.init(createInitArgs(instantSearchInstance, this, uiState)); } @@ -847,15 +835,6 @@ export const index = (widgetParams: IndexWidgetParams): IndexWidget => { ); }, - getWidgetState(uiState: UiState) { - warning( - false, - 'The `getWidgetState` method is renamed `getWidgetUiState` and will no longer exist under that name in InstantSearch.js 5.x. Please use `getWidgetUiState` instead.' - ); - - return this.getWidgetUiState(uiState); - }, - getWidgetSearchParameters(searchParameters, { uiState }) { return getLocalWidgetsSearchParameters(localWidgets, { uiState, diff --git a/packages/vue-instantsearch/src/util/__tests__/createServerRootMixin.test.js b/packages/vue-instantsearch/src/util/__tests__/createServerRootMixin.test.js index 70b4d57cda..938c961b65 100644 --- a/packages/vue-instantsearch/src/util/__tests__/createServerRootMixin.test.js +++ b/packages/vue-instantsearch/src/util/__tests__/createServerRootMixin.test.js @@ -1237,7 +1237,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/instantsear expect(renderArgs.createURL()).toBe('#'); }); - it('allows for widgets without getWidgetState', () => { + it('allows for widgets without getWidgetUiState', () => { let instantSearchInstance; mount({ mixins: [ @@ -1255,12 +1255,12 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/instantsear const widget = { init: jest.fn(), render: jest.fn(), - getWidgetState(uiState) { + getWidgetUiState(uiState) { return uiState; }, }; - const widgetWithoutGetWidgetState = { + const widgetWithoutGetWidgetUiState = { init: jest.fn(), render: jest.fn(), }; @@ -1269,7 +1269,10 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/instantsear lol: createSerializedState(), }); - instantSearchInstance.addWidgets([widget, widgetWithoutGetWidgetState]); + instantSearchInstance.addWidgets([ + widget, + widgetWithoutGetWidgetUiState, + ]); instantSearchInstance.__forceRender( widget,