Skip to main content

Upgrade templates

Starting from InstantSearch.js v4.46.0, string-based and Hogan.js templates are deprecated. If you’re using Hogan.js templates or HTML strings using string-based templates, you can replace them either with safe HTML strings using the provided html tagged template, or JSX templates. These new templating options are safer against cross-site scripting (XSS) attacks, perform better, and are more accessible, because they reuse and patch the existing DOM instead of replacing it entirely at each render. For more information, see:

Interpolation

You can interpolate dynamic values using template literals placeholders. All available dynamic values are exposed within the scope of the template function.

Highlighting and snippeting

In both hits and infiniteHits widgets, templates expose a set of built-in components to handle highlighting and snippeting.

Loops

You can use plain JavaScript to build dynamic templates. For example, you can use Array.mapto loop over an array and display a list.
Passing a unique key attribute is helpful when mapping over items. It helps the virtual DOM keep track of each element when they change, and update the UI efficiently.

Conditional rendering

To conditionally render a part of your UI, you can use a short-circuit operator or a ternary. Since templates are functions, you can also use conditional return statements to provide alternative templates.

Upgrade event tracking

Starting from v4.55.0, InstantSearch simplifies the event tracking process with the insights option. You no longer need to install the search-insights library or set up the insights middleware yourself. Here are some benefits when using the insights option:
  • It better handles the . Once you set it, all search and event tracking calls include the token.
  • It automatically sends default events from built-in widgets such as refinementList, menu, etc. You can also change the event payloads, or remove them altogether.
  • It lets you send custom events from your custom widgets.
  • It simplifies forwarding events to third-party trackers.
If you’ve been tracking events directly with search-insights or with the insights middleware, you should:
  1. Upgrade InstantSearch.js to v4.55.0 or greater
  2. Migrate from using the insights middleware to the insights option
  3. Either update or remove the search-insights library

Use the Insights option

Starting from v4.55.0, InstantSearch lets you enable event tracking with the insights option. You no longer need to set up the insights middleware yourself.
JavaScript
If you had already set up the insights middleware in your code, you can now remove it and move its configuration to the insights option.
JavaScript

Update search-insights

Starting from v4.55.0, InstantSearch can load search-insights for you so the insightsClient option is no longer required. If you prefer loading it yourself, make sure to update search-insights to at least v2.4.0 and forward the reference to insights. If you’re using the UMD bundle with a <script> tag, make sure to update the full code snippet (not just the version): If you’re using a package manager, you can upgrade it to the latest version.
Command line
Now you can pass the reference to the insights option.
Otherwise, you can remove it and let InstantSearch handle it for you.

Remove search-insights

Starting from v4.55.0, InstantSearch loads search-insights for you from jsDelivr if not detected in the page. If you’ve installed search-insights, you can now remove it. If you’re using the UMD bundle with a <script> tag, you can remove the snippet in any page that uses InstantSearch:
HTML
If you’re using a package manager, you can remove it from your dependencies.
Command line
Then you can remove the reference to search-insights from your code:
InstantSearch loads search-insights from the jsDelivr CDN, which requires that your site or app allows script execution from foreign resources. Check the security best practices for recommendations.

No longer needed configuration

clickAnalytics: true

JavaScript
This isn’t needed anymore because it’s automatically added by the middleware.

getInsightsAnonymousUserToken

JavaScript
You no longer need this. Once you integrate the insights middleware, it initially sets the anonymous userToken. As soon as you set another userToken, it automatically syncs it between search and analytics calls.

insightsClient at InstantSearch

JavaScript
Now that you are using the Insights middleware, you don’t need to pass aa to instantsearch() anymore.

hits and infiniteHits template

You might have templates in your hits or infiniteHits widgets that look like the following:
HTML
These are now deprecated. Instead, you can use the sendEvent function.
JavaScript

analytics widget

The analytics widget has been deprecated in favor of the insights middleware. When the built-in widgets trigger default events, you can intercept them using the insights middleware’s onEvent hook and send them to third-party trackers.
JavaScript
If you want to send events every time the or refinements change, you can add a custom middleware to listen to uiState changes with the onStateChange function.
JavaScript
You can also use external libraries like lodash.debounce to debounce the events you send.
JavaScript

Upgrade to Recommend

The relatedProducts widget is now available instead of the previous experimental widget EXPERIMENTAL_relatedItems. To migrate, you change the widget name and update the props:
JavaScript

Upgrade from v3 to v4

The latest version of InstantSearch focuses on federated search and bundle size. This required some changes that might impact your app.

Federated search (multi-index)

If you were already using federated search (for example by synchronizing two instantsearch instances with the searchFunction), the implementation is now simpler. Instead, try the new index widget, to which you can attach more widgets. For example:
JavaScript
To learn more, see Multi-index search with InstantSearch.js

Routing

Even if you aren’t using multi-index search, the way in which uiState is stored has changed. It used to look like this:
JSON
It now looks like this:
JSON
If you are using the default state mapping (simpleStateMapping) with the current version, you can replace it with singleIndexStateMapping('yourIndexName'). You have to change the code as followed:
JavaScript
If you are using a custom state mapping, you have to loop over the outer level of the index widget and add this extra level to the routeToState. You can check the source for a reference on how to implement this. For example, a stateMapping that maps a subset of properties would change like this:
JavaScript

Configure

The configure widget is now included in uiState. If you want to exclude it from the URL you can use the default stateMappings or exclude it in your custom state mapping. A good reason to exclude the configure widget from the UI state is to prevent users from adding any search parameters. You must exclude this widget in both the stateToRoute, to keep it from appearing in the URL and routeToState, so that the URL doesn’t apply to the state. Check the stateMapping source code for implementation details.

Algolia search helper

This release includes version 3 of the algoliasearch-helper package. If you’re using the built-in widgets or connectors, nothing changes for you. This version of algoliasearch-helper no longer includes Lodash, which reduces its bundle size (from 27.5 KB to 9.1 KB Gzipped). If you’re using any methods from the helper, searchParameters or searchResults, refer to the package’s change log.

Search parameters

The option searchParameters was removed from the instantsearch widget. You can replace it with the configure widget:
JavaScript
You can now add initialUiState to your InstantSearch widget. This overwrites specific searchParameters that are otherwise set during widget instantiation. initialUiState is only taken into account if a widget owning that “state” is mounted. A warning appears in development mode explaining which widget needs to be added for the UI state to have an effect. An example is a refinementList widget:
JavaScript

addWidget and removeWidget

The search.addWidget function is deprecated in favor of search.addWidgets, which accepts an array of widgets. Using arrays makes it clearer to see the structure of nested widgets. search.removeWidget is deprecated in favor of search.removeWidgets, which also accepts an array of widgets.

Custom widgets

Because version 3 of the algoliasearch-helper package is used, you have to replace the getConfiguration lifecycle with getWidgetSearchParameters and getWidgetState. This also means that your custom widget takes part in the routing. You can exclude it from the URL with stateMapping.
JavaScript
Becomes:
JavaScript

connectAutocomplete

The indices option was removed in favor of index widgets (see the federated search section). For example, the following code:
JavaScript
Should be replaced with this:
JavaScript

onHistoryChange

The onHistoryChange function is removed. To subscribe to changes in the URL, create a custom router and attach to the write hook. For example:
JavaScript

router

The dispose function on the router interface is now required and its signature is updated (see the example below). This change only impacts you if you use a custom router.
TypeScript

pagination

The noRefinementRoot CSS class gets added once there are no more possible refinements. It no longer gets applied on the first page, which was the wrong behavior.

Upgrade from v2 to v3

InstantSearch v3 introduces some breaking changes in the widgets’ naming, options, and markup.

What’s new

Search from your own search client

Since InstantSearch.js 2.8.0, it’s possible to search from your own backend using the searchClient option. This option is now the way to plug InstantSearch to either Algolia’s official JavaScript client or to yours. This means that the official search client isn’t bundled in InstantSearch, allowing for more flexibility. This results in a smaller bundle size when you’re not searching directly from the frontend, or that you use multiple instances of the search client.

Predictable DOM structure

InstantSearch.js v3 becomes more predictable by generating a DOM that follows Algolia’s InstantSearch.css specification. All flavors are now aligned, which makes it easier to migrate from one library flavor to another. The options and the DOM output are similar whether you use React InstantSearch, Vue InstantSearch, or InstantSearch.js.

Optimize InstantSearch based on your environment

The new bundle comes in two forms:
  • Development bundle. This is a heavier bundle that helps developers better debug in the development phase of an InstantSearch app. It’s more verbose and gives clues and warnings about the library usage.
  • Production bundle. This is a lighter bundle that doesn’t include any development warnings. Use this when deploying your app in a production environment.

Imports

UMD (Universal Module Definition)

New naming has been introduced for the UMD imports. This makes it clearer which InstantSearch.js bundle to use either in development or in production. The production bundle will get lighter over time as it won’t include the runtime warnings and documentation.
Before
After

CommonJS (CJS)

Before
JavaScript
After
JavaScript

ES (ECMAScript)

No changes.

InstantSearch

The variables appId and apiKey are replaced by searchClient.

Earlier usage

  1. Import InstantSearch.js
  2. Initialize InstantSearch
    JavaScript
New usage
  1. Import algoliasearch (prefer the lite version for search only)
  2. Import InstantSearch.js
  3. Initialize InstantSearch with the searchClient option
    JavaScript

transformData is replaced by transformItems

Since InstantSearch.js first public release, you can customize the values used in the widgets. This method was letting you map 1-1 the values with other values. With React InstantSearch, a slightly different API was implemented that lets you map over the list of values and to change their content.
Earlier usage
JavaScript
New usage
JavaScript

Highlights and snippets

Highlighting is a powerful tool for showing users why results match their queries. Earlier versions of InstantSearch used internal mechanisms or Hogan.js to implement highlighting within widget templates. Algolia now provides html tagged templates. For more information, see:
Earlier usage
New usage
JavaScript

urlSync is dropped

If you were using the urlSync option, you should now migrate to the new routing feature. Here are the elements you need to migrate:
  • urlSync: true becomes routing: true
  • threshold becomes routing: { router: instantsearch.routers.history({ writeDelay: 400 }) }
  • mapping and trackedParameters are replaced with stateMapping. Read “User friendly URLs” to know how to configure it
  • useHash is removed but can be achieved using an advanced configuration of the history router
  • getHistoryState is removed but can be achieved using an advanced configuration of the history router

collapsible is dropped

collapsible is replaced by the collapsed option in the panel widget.

autoHideContainer is dropped

autoHideContainer is replaced by the hidden option in the panel widget.

createAlgoliaClient is dropped

createAlgoliaClient is replaced by searchClient.

createQueryString is dropped

URL synchronization is done with Routing alone.

Widgets

CSS classes
Markup
HTML

ClearRefinements (formerly ClearAll)

Options
CSS classes
Markup
HTML

CurrentRefinements (formerly CurrentRefinedValues)

Options
  • clearsQuery can be replaced by excludedAtributes: [].
CSS classes
Markup
Default
HTML
With includesQuery and a query
HTML
Options
Since paddingBoundingBox conflicted with the routing option it was removed to support URLSync for the GeoSearch widget.
enableGeolocationWithIP
Before:
JavaScript
After:
JavaScript
position
Before:
JavaScript
After:
JavaScript
radius
Before:
JavaScript
After:
JavaScript
precision
Before:
JavaScript
After:
JavaScript
CSS classes
Markup
With the control element:
HTML
With the redo button:
HTML

Hits

Options
  • escapeHTML becomes true by default.
  • allItems template has been removed in favor of connectHits
CSS classes
Markup
HTML

HitPerPage (formerly HitsPerPageSelector)

Options
CSS classes
Markup
HTML

Infinite hits

Options
  • escapeHTML defaults to true
CSS classes
Markup
HTML

Hierarchical menu

Options
CSS classes
Markup
Default
HTML
Show more disabled
HTML
Options
  • showMore is now a boolean option (showMore.templates are now in templates)
  • sortBy defaults to ['isRefined', 'name:asc']
  • An object containing isShowingMore is passed to showMoreText template to toggle between the two states:
JavaScript
CSS classes
Markup
Default
HTML
Show more disabled
HTML
Options
CSS classes
Markup
HTML

NumericMenu (formerly NumericRefinementListe)

Options
The item name attribute is now named label.
CSS classes
Markup
HTML

NumericSelector

Widget removed.

Pagination

Options
CSS classes
Markup
HTML

PriceRanges

Widget removed.

RangeInput

Options
CSS classes
Markup
HTML

RangeSlider

Options
CSS classes
Markup
HTML

RatingMenu (formerly StarRating)

Options
The value for the label andUp is now inline inside templates.item.
CSS classes
Markup
HTML

RefinementList

Options
  • searchablePlaceholder defaults to "Search..."
  • searchableEscapeFacetValues defaults to true
  • searchableIsAlwaysActive defaults to true
  • showMore is now a boolean option (searchForFacetValues.templates and showMore.templates are now in templates)
  • An object containing isShowingMore is passed to showMoreText template to toggle between the two states:
JavaScript
CSS classes
Markup
Default
HTML
Show more disabled
HTML
With search and no results
HTML
Options
With the drop of wrapInput, it was decided not to accept inputs as containers anymore. If you want complete control over the rendering, use the connectSearchBox connector. The search box doesn’t support poweredBy. Algolia requires that you use this widget if you’re on a community plan (open source, not-for-profit, or DocSearch). Configuration options for reset, submit and loadingIndicator have been moved to templates and cssClasses. For example, for reset:
  • reset.template => templates.reset
  • reset.cssClasses.root => cssClasses.reset
autofocus is now set to false by default and doesn’t support the "auto" value anymore.
CSS classes
Markup
HTML

SortBy

Options
  • A sortBy item value is now value instead of name:
JavaScript
CSS classes
Markup
HTML

Stats

CSS classes
Markup
HTML

ToggleRefinement (formerly Toggle)

Options
collapsible and autoHideContainer options have been removed. These options are now implemented as part of the Panel widget wrapper. The label options has been moved into the templates.labelText template to make it consistent with the templates parameters of other widgets and the item template was removed. Data that was provided to templates.item is now provided to templates.labelText. If your attribute is called free_shipping, the default template displays “free_shipping”. To rename it, change templates.labelText to “Free shipping”.
CSS classes
Markup
HTML

Connectors

connectAutocomplete

Options
  • escapeHTML becomes true by default.

connectBreadcrumb

  • The BreadcrumbItem name property is renamed to label.

connectGeoSearch

Options
Since paddingBoundingBox conflicted with the routing option it was removed to support URLSync for the GeoSearch widget.
enableGeolocationWithIP
Before:
JavaScript
After:
JavaScript
position
Before:
JavaScript
After:
JavaScript
radius
Before:
JavaScript
After:
JavaScript
precision
Before:
JavaScript
After:
JavaScript

connectRange

Options

connectRangeSlider

Connector removed (use connectRange instead).

connectClearRefinements (formerly connectClearAll)

Options

connectNumericMenu (formerly connectNumericRefinementList)

Options
  • name becomes label

connectRefinementList

Options
  • escapeFacetValues defaults to true

connectCurrentRefinements (used to be connectCurrentRefinedValues)

Options
items (used to be refinements )
refinements used to be a flat list, now it’s called items (one per attribute), which each has its own list of refinements

Upgrade from v1 to v2

This guide has all the major changes that introduced in v2 with the description on how to migrate from v1.

The searchBox widget has new default options

To identify the input as a search box, a magnifying glass icon was placed at the start, and a reset button displayed as a cross at the end. You can customize the result with these two options:
  • reset boolan|{template?: string|Function, cssClasses?: {root: string}} Display a reset button in the input when there is a query.
  • magnifier boolan|{template?: string|Function, cssClasses?: {root: string}} Display a magnifier should at beginning of the input.
To make the search box like in v1, you can do the following:
JavaScript
You can read more about these options on the searchBox API reference.

No more hitsPerPage in hits and infiniteHits

This option was removed from those two widgets. To configure this option of the engine, there are still three ways:
  • Use the dashboard or the client, to change the setting at the index level.
  • Use the hitsPerPage widget.
  • Use the configuration option of instantsearch:
JavaScript

The items aren’t sorted like before in the refinementList / menu

The default sort order of those widgets has changed. This might have affected your implementation if you didn’t specify them originally. To change back the order use the sortBy configuration key. Here are examples of usage of sortBy using the previous sorting scheme:
JavaScript
If you want to learn more about sorting the values, check out the widget API to see what are the valid values for the sortBy option of menu or refinementList

Some variables have been changed

Internally all the widgets are now using the connectors. The aim was to ensure the API was as close to the one offered by react-instantsearch connectors. This then affected the name of some variables in the templates and the API. Changes in templates:
  • In the item template of the hierarchicalMenu and menu widgets, name becomes label
  • In the item template of the refinementList widget, name becomes value.
Changes in the API:
  • In hitsPerPageSelector, the options was renamed to items.

React components can’t be used as templates

When InstantSearch.js was created it was built using React and it wasn’t known that react-instantsearch would be built. react-instantsearch is now the recommended solution if your app uses React. That’s why support for the React based templates was dropped in this release. Algolia considers the engine used to build the widgets in InstantSearch.js to be an implementation detail. Since it isn’t exposed anymore, Algolia can change it and use the best solution for each release.

rangeSlider widget is using Rheostat as Slider Component

Slider components are hard to implement and that’s why Algolia relies on an external component for that. Algolia is taking the opportunity of this new version to switch to the current ‘state of the art’ of sliders: Rheostat. If you want to customize the style, some CSS classes have changed. The look is still similar as the one in the V1.

searchFunction can be used to change parameters

Introduced in 1.3.0, searchFunction was originally meant as a way to change the timing of the search. However it was realized that it was a good way to alter the search state before making the actual state. This is what’s required to force the query string:
JavaScript
And now, it’s more straightforward:
JavaScript
The helper still resets the page to 0 when the parameters change. To keep the page you set, do the following:
JavaScript
Last modified on July 10, 2026