Upgrade event tracking
Starting from v4.9.0, Vue InstantSearch simplifies the event tracking process with theinsights 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
userToken. Once you set it, all the search and event tracking calls include the token. - It automatically sends default events from built-in widgets such as
ais-refinement-list,ais-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.
search-insights or with the insights middleware, you should:
- Upgrade Vue InstantSearch to v4.9.0 or greater
- Migrate from using the
insightsmiddleware to theinsightsoption - Either update or remove the
search-insightslibrary
Use the insights option
Starting from v4.9.0, Vue InstantSearch lets you enable event tracking with theinsights option. You no longer need to set up the insights middleware yourself.
Vue
insights middleware in your code, you can now remove it and move its configuration to the insights option.
Vue
Update search-insights
Starting from v4.9.0, Vue 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):
HTML
insights option.
Remove search-insights
Starting from v4.9.0, Vue 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 Vue InstantSearch:
HTML
search-insights from your code:
Vue 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.Upgrade from v3 to v4
You can use Vue InstantSearch v4 with Vue 2 and Vue 3.Server-side rendering
Using Vue InstantSearch v4 introduces one breaking change in the server-side rendering.findResultsState in serverPrefetch now takes component and renderToString: (app) => Promise<string> in the first argument.
Vue 3
JavaScript
Vue 2
The renderToString function fromvue-server-renderer/basic is callback-based.
You need to promisify it like this:
JavaScript
If you upgrade to Vue 3
Import the library
The path to import Vue InstantSearch has changed for Vue 3, and is now:JavaScript
Vue Router v4
If you’re using Vue Router and upgrading it to v4,currentRoute is now a reference instead of an object.
JavaScript
Upgrade from v2 to v3
This guide contains all the major changes that were introduced in v3, and how to migrate from v2. Vue InstantSearch v3 uses InstantSearch.js v4, so all breaking changes using the InstantSearch.js API also apply here. You can find more information in its respective upgrade guide.Federated search (multi-index)
If you were using aais-configure or a ais-search-box to synchronize between two ais-instant-search instances, you can now replace either one of them with the new ais-index widget like this:
Vue
ais-autocomplete
Theindices option has been removed in favor of ais-index.
This means that:
Vue
Vue
ais-state-results
This widget used to expose the search results only, you can now access the search parameters as well. This lets you use query information to perform view logic instead of waiting for the response to retrieve the data.Vue
Routing and URLs
Since the introduction of federated search, it’s now possible to have multiple indices in a single app. This means that the default state mapping for routing now takes multiple indices into account. If you want to keep on using the same URLs as before, make the following change:JavaScript
Server-side rendering (SSR)
This major version of Vue InstantSearch also includes an overhaul of the server-side rendering implementation. This takes two points into consideration:- work fully with
serverPrefetch - no repetition needed between the template and parameters
-
createInstantSearch->createServerRootMixinJavaScript -
Using a compatible router
The default routers in InstantSearch.js are based around browser location,
and thus won’t work on the server. An example router for Vue SSR can be made like this:
JavaScript
Helper v3.x.x
This release includes version 3 of thealgoliasearch-helper package. If you are using the built-in widgets or connectors, nothing changes for you.
This version of algoliasearch-helper no longer includes Lodash, which significantly reduces its bundle size (from 27.5 KB to 9.1 KB Gzipped).
Upgrade from v1 to v2
This guide contains all the major changes that were introduced in v2 and how to migrate from v1. You can still find the documentation for Vue InstantSearch v1.Renamed components
Some components have been renamed to be more consistent with other InstantSearch flavors.ais-results->ais-hitsais-tree-menu->ais-hierarchical-menuais-clear->ais-clear-refinementsais-results-per-page-selector->ais-hits-per-pageais-rating->ais-rating-menuais-sort-by-selector->ais-sort-byais-index->ais-instant-search
SearchBox to AisSearchBox. This is to make it more ergonomic to use them as components in a Vue file with the same name as expected.
The Component mixin has been renamed to createWidgetMixin({ connector }). Read more about that in the custom component guide.
New components
-
ais-configureThis widget is the replacement ofquery-parametersonais-index. -
ais-state-resultsThis component can be used for conditional rendering, and getting information that’s not returned inais-hits. -
ais-breadcrumbTo be used together withais-hierarchical-menu. -
ais-menu-selectA single-selectable menu, rendered inside aselect -
ais-current-refinementsShows the current refinements, and allows them to be unset. -
ais-infinite-hitsReplaces:stack="true"onais-results(now calledais-hits). -
ais-numeric-menuStatically set numerical ranges can be used to refine using this widget. -
ais-panelWrap a widget inais-panelto be able to give it a header and a footer. Replaces those options on each widget. -
ais-toggle-refinementToggle a boolean refinement either refined/unrefined or refinement/another refinement. Useful for toggles or buttons with two states.
Renamed options
Some options have been renamed. Largely those are:- attribute-name -> attribute
- results -> hits
- anything in a list -> items / item
- header / footer -> wrap the widget in an
ais-panel
Removed options
-
query-parametersThis is now handled with theais-configurewidget. Each query parameter becomes a prop on Configure. -
queryYou can now synchronize the query across indices either by using av-modelon twoais-search-boxes of which you hide one, or withais-configureon both indices, and synchronizing between those like that. -
appIdandapiKeyThis is now handled by thesearch-clientprop. Search client is what gets returned if you callalgoliasearch.Vue -
:stack="true"When you used to put this onais-results(now calledais-hits), it allows to load next pages without pagination, but with a “next page” button, as well as showing all pages rather than a single one. Replaced byais-infinite-hits. -
auto-searchThis option is removed in favor of a more complete way of not doing queries using the search client. For more information, see Conditional requests.
Removed components
-
ais-inputThis component has been removed with as alternative having two options:- use
ais-search-boxand style it to not include the extra items - use the default slot of
ais-search-boxto use it with your own custom input (see live):
Vue - use
CSS class names
All CSS class names are now different, since Algolia follows the SUIT CSS methodology now, rather than the previous, slightly wrong, implementation of ‘block, element and modifier’ (BEM). Since the DOM output is also different in most widgets, it’s best to start styling over from scratch on these widgets. Each widget lists the CSS classes it uses in its documentation page.Known limitations
SSR (server-side rendering)
The implementation of server-side rendering with Vue InstantSearch slightly changed, with a simpler API. Read more on how to use it in the SSR guide.Search store
The search store no longer exists. Custom widgets are either made by making a connector, or a combination of new widgets. You no longer need to copy a widget to give it custom rendering. Now you can fill in thedefault slot, which will have everything needed to render that component.
If you’re using this, and have suggestions or questions, please complete the feedback form.
Routing
You’re now able to use routing in InstantSearch with, or without Vue Router.Changing props on ais-instant-search
It’s possible to change props onais-instant-search, except routing. If you have a need for that to be changed as well, please complete the feedback form.