instantsearch.js 4.75.4 → 4.75.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/cjs/components/Slider/Rheostat.js +4 -4
  2. package/cjs/connectors/autocomplete/connectAutocomplete.js +9 -5
  3. package/cjs/connectors/current-refinements/connectCurrentRefinements.js +1 -1
  4. package/cjs/connectors/hits/connectHitsWithInsights.js +3 -1
  5. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +1 -1
  6. package/cjs/connectors/infinite-hits/connectInfiniteHitsWithInsights.js +3 -1
  7. package/cjs/lib/InstantSearch.js +2 -0
  8. package/cjs/lib/server.js +5 -2
  9. package/cjs/lib/utils/getRefinements.js +2 -1
  10. package/cjs/lib/version.js +1 -1
  11. package/cjs/middlewares/createInsightsMiddleware.js +38 -79
  12. package/cjs/widgets/analytics/analytics.js +3 -0
  13. package/cjs/widgets/hits/defaultTemplates.js +1 -0
  14. package/cjs/widgets/index/index.js +0 -1
  15. package/cjs/widgets/places/places.js +2 -0
  16. package/dist/instantsearch.development.d.ts +7 -7
  17. package/dist/instantsearch.development.js +84 -110
  18. package/dist/instantsearch.development.js.map +1 -1
  19. package/dist/instantsearch.production.d.ts +7 -7
  20. package/dist/instantsearch.production.min.d.ts +7 -7
  21. package/dist/instantsearch.production.min.js +2 -2
  22. package/dist/instantsearch.production.min.js.map +1 -1
  23. package/es/connectors/autocomplete/connectAutocomplete.js +9 -5
  24. package/es/connectors/current-refinements/connectCurrentRefinements.js +1 -1
  25. package/es/connectors/hits/connectHitsWithInsights.js +3 -1
  26. package/es/connectors/infinite-hits/connectInfiniteHits.d.ts +1 -1
  27. package/es/connectors/infinite-hits/connectInfiniteHits.js +1 -1
  28. package/es/connectors/infinite-hits/connectInfiniteHitsWithInsights.js +3 -1
  29. package/es/lib/InstantSearch.js +2 -0
  30. package/es/lib/server.js +5 -2
  31. package/es/lib/utils/getRefinements.d.ts +1 -1
  32. package/es/lib/utils/getRefinements.js +2 -1
  33. package/es/lib/utils/render-args.d.ts +1 -1
  34. package/es/lib/version.d.ts +1 -1
  35. package/es/lib/version.js +1 -1
  36. package/es/middlewares/createInsightsMiddleware.d.ts +1 -1
  37. package/es/middlewares/createInsightsMiddleware.js +38 -79
  38. package/es/types/insights.d.ts +2 -2
  39. package/es/types/widget.d.ts +3 -3
  40. package/es/widgets/analytics/analytics.js +3 -0
  41. package/es/widgets/hits/defaultTemplates.js +1 -0
  42. package/es/widgets/index/index.js +0 -1
  43. package/es/widgets/places/places.js +2 -0
  44. package/es/widgets/search-box/defaultTemplates.js +0 -1
  45. package/package.json +7 -7
@@ -20,10 +20,10 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
20
20
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
21
21
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
22
22
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } /**
23
- * This is a fork of Rheostat for Preact X.
24
- *
25
- * @see https://github.com/airbnb/rheostat
26
- */
23
+ * This is a fork of Rheostat for Preact X.
24
+ *
25
+ * @see https://github.com/airbnb/rheostat
26
+ */
27
27
  var KEYS = {
28
28
  DOWN: 40,
29
29
  END: 35,
@@ -64,21 +64,25 @@ var connectAutocomplete = function connectAutocomplete(renderFn) {
64
64
  };
65
65
  }
66
66
  var indices = scopedResults.map(function (scopedResult) {
67
+ var _scopedResult$results2, _scopedResult$results3;
67
68
  // We need to escape the hits because highlighting
68
69
  // exposes HTML tags to the end-user.
69
- scopedResult.results.hits = escapeHTML ? (0, _utils.escapeHits)(scopedResult.results.hits) : scopedResult.results.hits;
70
+ if (scopedResult.results) {
71
+ scopedResult.results.hits = escapeHTML ? (0, _utils.escapeHits)(scopedResult.results.hits) : scopedResult.results.hits;
72
+ }
70
73
  var sendEvent = (0, _utils.createSendEventForHits)({
71
74
  instantSearchInstance: instantSearchInstance,
72
75
  getIndex: function getIndex() {
73
- return scopedResult.results.index;
76
+ var _scopedResult$results;
77
+ return ((_scopedResult$results = scopedResult.results) === null || _scopedResult$results === void 0 ? void 0 : _scopedResult$results.index) || '';
74
78
  },
75
79
  widgetType: _this.$$type
76
80
  });
77
81
  return {
78
82
  indexId: scopedResult.indexId,
79
- indexName: scopedResult.results.index,
80
- hits: scopedResult.results.hits,
81
- results: scopedResult.results,
83
+ indexName: ((_scopedResult$results2 = scopedResult.results) === null || _scopedResult$results2 === void 0 ? void 0 : _scopedResult$results2.index) || '',
84
+ hits: ((_scopedResult$results3 = scopedResult.results) === null || _scopedResult$results3 === void 0 ? void 0 : _scopedResult$results3.hits) || [],
85
+ results: scopedResult.results || {},
82
86
  sendEvent: sendEvent
83
87
  };
84
88
  });
@@ -66,7 +66,7 @@ var connectCurrentRefinements = function connectCurrentRefinements(renderFn) {
66
66
  function getItems() {
67
67
  if (!results) {
68
68
  return transformItems(getRefinementsItems({
69
- results: {},
69
+ results: null,
70
70
  helper: helper,
71
71
  indexId: helper.state.index,
72
72
  includedAttributes: includedAttributes,
@@ -11,7 +11,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
11
11
  * Due to https://github.com/microsoft/web-build-tools/issues/1050, we need
12
12
  * Connector<...> imported in this file, even though it is only used implicitly.
13
13
  * This _uses_ Connector<...> so it is not accidentally removed by someone.
14
- */ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
+ */
15
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
+
15
17
  var connectHitsWithInsights = (0, _insights.withInsights)(_connectHits.default);
16
18
  var _default = connectHitsWithInsights;
17
19
  exports.default = _default;
@@ -222,7 +222,7 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
222
222
  sendEvent: sendEvent,
223
223
  bindEvent: bindEvent,
224
224
  banner: banner,
225
- results: results,
225
+ results: results || undefined,
226
226
  showPrevious: showPrevious,
227
227
  showMore: showMore,
228
228
  isFirstPage: isFirstPage,
@@ -11,7 +11,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
11
11
  * Due to https://github.com/microsoft/web-build-tools/issues/1050, we need
12
12
  * Connector<...> imported in this file, even though it is only used implicitly.
13
13
  * This _uses_ Connector<...> so it is not accidentally removed by someone.
14
- */ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
+ */
15
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
+
15
17
  var connectInfiniteHitsWithInsights = (0, _insights.withInsights)(_connectInfiniteHits.default);
16
18
  var _default = connectInfiniteHitsWithInsights;
17
19
  exports.default = _default;
@@ -40,9 +40,11 @@ function defaultCreateURL() {
40
40
  // this purposely breaks typescript's type inference to ensure it's not used
41
41
  // as it's used for a default parameter for example
42
42
  // source: https://github.com/Microsoft/TypeScript/issues/14829#issuecomment-504042546
43
+
43
44
  /**
44
45
  * Global options for an InstantSearch instance.
45
46
  */
47
+
46
48
  var INSTANTSEARCH_FUTURE_DEFAULTS = {
47
49
  preserveSharedStateOnUnmount: false,
48
50
  persistHierarchicalRootCount: false
package/cjs/lib/server.js CHANGED
@@ -85,12 +85,15 @@ requestParamsList) {
85
85
  var searchResults = widget.getResults();
86
86
  var recommendResults = (_widget$getHelper = widget.getHelper()) === null || _widget$getHelper === void 0 ? void 0 : _widget$getHelper.lastRecommendResults;
87
87
  if (searchResults || recommendResults) {
88
- var _searchResults$_rawRe;
88
+ var _searchResults$_rawRe, _requestParams$, _requestParams$2;
89
89
  var resultsCount = (searchResults === null || searchResults === void 0 ? void 0 : (_searchResults$_rawRe = searchResults._rawResults) === null || _searchResults$_rawRe === void 0 ? void 0 : _searchResults$_rawRe.length) || 0;
90
90
  var requestParams = resultsCount ? requestParamsList === null || requestParamsList === void 0 ? void 0 : requestParamsList.slice(requestParamsIndex, requestParamsIndex + resultsCount) : [];
91
91
  requestParamsIndex += resultsCount;
92
92
  initialResults[widget.getIndexId()] = _objectSpread(_objectSpread(_objectSpread({}, searchResults && {
93
- state: _objectSpread({}, searchResults._state),
93
+ state: _objectSpread(_objectSpread({}, searchResults._state), {}, {
94
+ clickAnalytics: requestParams === null || requestParams === void 0 ? void 0 : (_requestParams$ = requestParams[0]) === null || _requestParams$ === void 0 ? void 0 : _requestParams$.clickAnalytics,
95
+ userToken: requestParams === null || requestParams === void 0 ? void 0 : (_requestParams$2 = requestParams[0]) === null || _requestParams$2 === void 0 ? void 0 : _requestParams$2.userToken
96
+ }),
94
97
  results: searchResults._rawResults
95
98
  }), recommendResults && {
96
99
  recommendResults: {
@@ -46,8 +46,9 @@ function getRefinement(state, type, attribute, name) {
46
46
  }
47
47
  return res;
48
48
  }
49
- function getRefinements(results, state) {
49
+ function getRefinements(_results, state) {
50
50
  var includesQuery = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
51
+ var results = _results || {};
51
52
  var refinements = [];
52
53
  var _state$facetsRefineme = state.facetsRefinements,
53
54
  facetsRefinements = _state$facetsRefineme === void 0 ? {} : _state$facetsRefineme,
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '4.75.4';
7
+ var _default = '4.75.6';
8
8
  exports.default = _default;
@@ -23,7 +23,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
23
23
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
24
24
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
25
25
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
26
- var ALGOLIA_INSIGHTS_VERSION = '2.15.0';
26
+ var ALGOLIA_INSIGHTS_VERSION = '2.17.2';
27
27
  var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights@".concat(ALGOLIA_INSIGHTS_VERSION, "/dist/search-insights.min.js");
28
28
  function createInsightsMiddleware() {
29
29
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -34,7 +34,6 @@ function createInsightsMiddleware() {
34
34
  $$internal = _props$$$internal === void 0 ? false : _props$$$internal,
35
35
  _props$$$automatic = props.$$automatic,
36
36
  $$automatic = _props$$$automatic === void 0 ? false : _props$$$automatic;
37
- var currentTokenType;
38
37
  var potentialInsightsClient = _insightsClient;
39
38
  if (!_insightsClient && _insightsClient !== null) {
40
39
  (0, _utils.safelyRunOnBrowser)(function (_ref) {
@@ -83,9 +82,7 @@ function createInsightsMiddleware() {
83
82
  process.env.NODE_ENV === 'development' ? (0, _utils.warning)(Boolean(appId && apiKey), 'could not extract Algolia credentials from searchClient in insights middleware.') : void 0;
84
83
  var queuedInitParams = undefined;
85
84
  var queuedUserToken = undefined;
86
- var queuedAuthenticatedUserToken = undefined;
87
85
  var userTokenBeforeInit = undefined;
88
- var authenticatedUserTokenBeforeInit = undefined;
89
86
  var queue = insightsClient.queue;
90
87
  if (Array.isArray(queue)) {
91
88
  // Context: The umd build of search-insights is asynchronously loaded by the snippet.
@@ -98,7 +95,7 @@ function createInsightsMiddleware() {
98
95
  // At this point, even though `search-insights` is not loaded yet,
99
96
  // we still want to read the token from the queue.
100
97
  // Otherwise, the first search call will be fired without the token.
101
- var _map = ['setUserToken', 'setAuthenticatedUserToken', 'init'].map(function (key) {
98
+ var _map = ['setUserToken', 'init'].map(function (key) {
102
99
  var _ref3 = (0, _utils.find)(queue.slice().reverse(), function (_ref5) {
103
100
  var _ref6 = _slicedToArray(_ref5, 1),
104
101
  method = _ref6[0];
@@ -108,23 +105,18 @@ function createInsightsMiddleware() {
108
105
  value = _ref4[1];
109
106
  return value;
110
107
  });
111
- var _map2 = _slicedToArray(_map, 3);
108
+ var _map2 = _slicedToArray(_map, 2);
112
109
  queuedUserToken = _map2[0];
113
- queuedAuthenticatedUserToken = _map2[1];
114
- queuedInitParams = _map2[2];
110
+ queuedInitParams = _map2[1];
115
111
  }
116
112
 
117
- // If user called `aa('setUserToken')` or `aa('setAuthenticatedUserToken')`
118
- // before creating the Insights middleware, we temporarily store the token
119
- // and set it later on.
113
+ // If user called `aa('setUserToken')` before creating the Insights middleware,
114
+ // we temporarily store the token and set it later on.
120
115
  //
121
116
  // Otherwise, the `init` call might override them with anonymous user token.
122
117
  insightsClient('getUserToken', null, function (_error, userToken) {
123
118
  userTokenBeforeInit = normalizeUserToken(userToken);
124
119
  });
125
- insightsClient('getAuthenticatedUserToken', null, function (_error, userToken) {
126
- authenticatedUserTokenBeforeInit = normalizeUserToken(userToken);
127
- });
128
120
 
129
121
  // Only `init` if the `insightsInitParams` option is passed or
130
122
  // if the `insightsClient` version doesn't supports optional `init` calling.
@@ -164,7 +156,7 @@ function createInsightsMiddleware() {
164
156
  helper = instantSearchInstance.mainHelper;
165
157
  var queueAtStart = insightsClient.queue;
166
158
  if (Array.isArray(queueAtStart)) {
167
- var _map3 = ['setUserToken', 'setAuthenticatedUserToken', 'init'].map(function (key) {
159
+ var _map3 = ['setUserToken', 'init'].map(function (key) {
168
160
  var _ref7 = (0, _utils.find)(queueAtStart.slice().reverse(), function (_ref9) {
169
161
  var _ref10 = _slicedToArray(_ref9, 1),
170
162
  method = _ref10[0];
@@ -174,15 +166,11 @@ function createInsightsMiddleware() {
174
166
  value = _ref8[1];
175
167
  return value;
176
168
  });
177
- var _map4 = _slicedToArray(_map3, 3);
169
+ var _map4 = _slicedToArray(_map3, 2);
178
170
  queuedUserToken = _map4[0];
179
- queuedAuthenticatedUserToken = _map4[1];
180
- queuedInitParams = _map4[2];
171
+ queuedInitParams = _map4[1];
181
172
  }
182
- initialParameters = {
183
- userToken: helper.state.userToken,
184
- clickAnalytics: helper.state.clickAnalytics
185
- };
173
+ initialParameters = getInitialParameters(instantSearchInstance);
186
174
 
187
175
  // We don't want to force clickAnalytics when the insights is enabled from the search response.
188
176
  // This means we don't enable insights for indices that don't opt in
@@ -194,9 +182,8 @@ function createInsightsMiddleware() {
194
182
  if (!$$internal) {
195
183
  instantSearchInstance.scheduleSearch();
196
184
  }
197
- var setUserTokenToSearch = function setUserTokenToSearch(userToken, tokenType) {
198
- var immediate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
199
- var unsetAuthenticatedUserToken = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
185
+ var setUserTokenToSearch = function setUserTokenToSearch(userToken) {
186
+ var immediate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
200
187
  var normalizedUserToken = normalizeUserToken(userToken);
201
188
  if (!normalizedUserToken) {
202
189
  return;
@@ -209,13 +196,6 @@ function createInsightsMiddleware() {
209
196
  if (existingToken && existingToken !== userToken) {
210
197
  instantSearchInstance.scheduleSearch();
211
198
  }
212
- currentTokenType = tokenType;
213
- }
214
-
215
- // the authenticated user token cannot be overridden by a user or anonymous token
216
- // for instant search query requests
217
- if (currentTokenType && currentTokenType === 'authenticated' && tokenType === 'default' && !unsetAuthenticatedUserToken) {
218
- return;
219
199
  }
220
200
 
221
201
  // Delay the token application to the next render cycle
@@ -225,14 +205,9 @@ function createInsightsMiddleware() {
225
205
  applyToken();
226
206
  }
227
207
  };
228
- function setUserToken(token, userToken, authenticatedUserToken) {
229
- setUserTokenToSearch(token, authenticatedUserToken ? 'authenticated' : 'default', true);
230
- if (userToken) {
231
- insightsClient('setUserToken', userToken);
232
- }
233
- if (authenticatedUserToken) {
234
- insightsClient('setAuthenticatedUserToken', authenticatedUserToken);
235
- }
208
+ function setUserToken(token) {
209
+ setUserTokenToSearch(token, true);
210
+ insightsClient('setUserToken', token);
236
211
  }
237
212
  var anonymousUserToken = undefined;
238
213
  var anonymousTokenFromInsights = (0, _helpers.getInsightsAnonymousUserTokenInternal)();
@@ -246,7 +221,6 @@ function createInsightsMiddleware() {
246
221
  var token = "anonymous-".concat((0, _uuid.createUUID)());
247
222
  anonymousUserToken = token;
248
223
  }
249
- var authenticatedUserTokenFromInit;
250
224
  var userTokenFromInit;
251
225
 
252
226
  // With SSR, the token could be be set on the state. We make sure
@@ -254,36 +228,25 @@ function createInsightsMiddleware() {
254
228
  // insights lib on the server.
255
229
  var tokenFromSearchParameters = initialParameters.userToken;
256
230
 
257
- // When the first query is sent, the token is possibly not yet be set by
231
+ // When the first query is sent, the token is possibly not yet set by
258
232
  // the insights onChange callbacks (if insights isn't yet loaded).
259
233
  // It is explicitly being set here so that the first query has the
260
234
  // initial tokens set and ensure a second query isn't automatically
261
235
  // made when the onChange callback actually changes the state.
262
- if (insightsInitParams) {
263
- if (insightsInitParams.authenticatedUserToken) {
264
- authenticatedUserTokenFromInit = insightsInitParams.authenticatedUserToken;
265
- } else if (insightsInitParams.userToken) {
266
- userTokenFromInit = insightsInitParams.userToken;
267
- }
236
+ if (insightsInitParams !== null && insightsInitParams !== void 0 && insightsInitParams.userToken) {
237
+ userTokenFromInit = insightsInitParams.userToken;
268
238
  }
269
-
270
- // We consider the `userToken` or `authenticatedUserToken` before an
271
- // `init` call of higher importance than one from the queue and ones set
272
- // from the init props to be higher than that.
273
- var tokenFromInit = authenticatedUserTokenFromInit || userTokenFromInit;
274
- var tokenBeforeInit = authenticatedUserTokenBeforeInit || userTokenBeforeInit;
275
- var tokenFromQueue = queuedAuthenticatedUserToken || queuedUserToken;
276
- if (tokenFromInit) {
277
- setUserToken(tokenFromInit, userTokenFromInit, authenticatedUserTokenFromInit);
239
+ if (userTokenFromInit) {
240
+ setUserToken(userTokenFromInit);
278
241
  } else if (tokenFromSearchParameters) {
279
- setUserToken(tokenFromSearchParameters, tokenFromSearchParameters, undefined);
280
- } else if (tokenBeforeInit) {
281
- setUserToken(tokenBeforeInit, userTokenBeforeInit, authenticatedUserTokenBeforeInit);
282
- } else if (tokenFromQueue) {
283
- setUserToken(tokenFromQueue, queuedUserToken, queuedAuthenticatedUserToken);
242
+ setUserToken(tokenFromSearchParameters);
243
+ } else if (userTokenBeforeInit) {
244
+ setUserToken(userTokenBeforeInit);
245
+ } else if (queuedUserToken) {
246
+ setUserToken(queuedUserToken);
284
247
  } else if (anonymousUserToken) {
285
248
  var _queuedInitParams;
286
- setUserToken(anonymousUserToken, anonymousUserToken, undefined);
249
+ setUserToken(anonymousUserToken);
287
250
  if (insightsInitParams !== null && insightsInitParams !== void 0 && insightsInitParams.useCookie || (_queuedInitParams = queuedInitParams) !== null && _queuedInitParams !== void 0 && _queuedInitParams.useCookie) {
288
251
  var _queuedInitParams2;
289
252
  saveTokenAsCookie(anonymousUserToken, (insightsInitParams === null || insightsInitParams === void 0 ? void 0 : insightsInitParams.cookieDuration) || ((_queuedInitParams2 = queuedInitParams) === null || _queuedInitParams2 === void 0 ? void 0 : _queuedInitParams2.cookieDuration));
@@ -292,20 +255,7 @@ function createInsightsMiddleware() {
292
255
 
293
256
  // This updates userToken which is set explicitly by `aa('setUserToken', userToken)`
294
257
  insightsClient('onUserTokenChange', function (token) {
295
- return setUserTokenToSearch(token, 'default', true);
296
- }, {
297
- immediate: true
298
- });
299
-
300
- // This updates userToken which is set explicitly by `aa('setAuthenticatedtUserToken', authenticatedUserToken)`
301
- insightsClient('onAuthenticatedUserTokenChange', function (authenticatedUserToken) {
302
- // If we're unsetting the `authenticatedUserToken`, we revert to the `userToken`
303
- if (!authenticatedUserToken) {
304
- insightsClient('getUserToken', null, function (_, userToken) {
305
- setUserTokenToSearch(userToken, 'default', true, true);
306
- });
307
- }
308
- setUserTokenToSearch(authenticatedUserToken, 'authenticated', true);
258
+ return setUserTokenToSearch(token, true);
309
259
  }, {
310
260
  immediate: true
311
261
  });
@@ -327,7 +277,7 @@ function createInsightsMiddleware() {
327
277
  var lastQueryId;
328
278
  instantSearchInstance.mainHelper.derivedHelpers[0].on('result', function (_ref11) {
329
279
  var results = _ref11.results;
330
- if (!results.queryID || results.queryID !== lastQueryId) {
280
+ if (results && (!results.queryID || results.queryID !== lastQueryId)) {
331
281
  lastQueryId = results.queryID;
332
282
  viewedObjectIDs.clear();
333
283
  }
@@ -367,7 +317,6 @@ function createInsightsMiddleware() {
367
317
  },
368
318
  unsubscribe: function unsubscribe() {
369
319
  insightsClient('onUserTokenChange', undefined);
370
- insightsClient('onAuthenticatedUserTokenChange', undefined);
371
320
  instantSearchInstance.sendEventToInsights = _utils.noop;
372
321
  if (helper && initialParameters) {
373
322
  helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread(_objectSpread({}, helper.state), initialParameters));
@@ -377,6 +326,16 @@ function createInsightsMiddleware() {
377
326
  };
378
327
  };
379
328
  }
329
+ function getInitialParameters(instantSearchInstance) {
330
+ var _instantSearchInstanc, _instantSearchInstanc2;
331
+ // in SSR, the initial state we use in this domain is set on the main index
332
+ var stateFromInitialResults = ((_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : (_instantSearchInstanc2 = _instantSearchInstanc[instantSearchInstance.indexName]) === null || _instantSearchInstanc2 === void 0 ? void 0 : _instantSearchInstanc2.state) || {};
333
+ var stateFromHelper = instantSearchInstance.mainHelper.state;
334
+ return {
335
+ userToken: stateFromInitialResults.userToken || stateFromHelper.userToken,
336
+ clickAnalytics: stateFromInitialResults.clickAnalytics || stateFromHelper.clickAnalytics
337
+ };
338
+ }
380
339
  function saveTokenAsCookie(token, cookieDuration) {
381
340
  var MONTH = 30 * 24 * 60 * 60 * 1000;
382
341
  var d = new Date();
@@ -124,6 +124,9 @@ var analytics = function analytics(widgetParams) {
124
124
  render: function render(_ref2) {
125
125
  var results = _ref2.results,
126
126
  state = _ref2.state;
127
+ if (!results) {
128
+ return;
129
+ }
127
130
  if (isInitialSearch === true) {
128
131
  isInitialSearch = false;
129
132
  return;
@@ -7,6 +7,7 @@ exports.default = void 0;
7
7
  var _utils = require("../../lib/utils");
8
8
  // false positive lint error
9
9
  // eslint-disable-next-line @typescript-eslint/consistent-type-imports
10
+
10
11
  var defaultTemplates = {
11
12
  empty: function empty() {
12
13
  return 'No results';
@@ -53,7 +53,6 @@ function privateHelperSetState(helper, _ref) {
53
53
  // TODO: emit "change" event when events for Recommend are implemented
54
54
  }
55
55
  }
56
-
57
56
  function getLocalWidgetsUiState(widgets, widgetStateOptions) {
58
57
  var initialUiState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
59
58
  return widgets.reduce(function (uiState, widget) {
@@ -17,7 +17,9 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
17
17
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
18
18
  /* Places.js is an optional dependency, no error should be reported if the package is missing */
19
19
  /** @ts-ignore */
20
+
20
21
  // using the type like this requires only one ts-ignore
22
+
21
23
  /**
22
24
  * This widget sets the geolocation value for the search based on the selected
23
25
  * result in the Algolia Places autocomplete.
@@ -4902,7 +4902,7 @@ declare type InfiniteHitsRenderState<THit extends NonNullable<object> = BaseHit>
4902
4902
  /**
4903
4903
  * The response from the Algolia API.
4904
4904
  */
4905
- results?: SearchResults<Hit<THit>>;
4905
+ results?: SearchResults<Hit<THit>> | null;
4906
4906
  /**
4907
4907
  * The banner to display above the hits.
4908
4908
  */
@@ -5018,7 +5018,7 @@ declare type InsightsEvent<TMethod extends InsightsMethod = InsightsMethod> = In
5018
5018
  */
5019
5019
  declare type InsightsEvent_2<TMethod extends InsightsMethod = InsightsMethod> = {
5020
5020
  insightsMethod?: TMethod;
5021
- payload: InsightsMethodMap[TMethod][0];
5021
+ payload: InsightsMethodMap[TMethod][0][0];
5022
5022
  widgetType: string;
5023
5023
  eventType: string;
5024
5024
  eventModifier?: string;
@@ -5035,7 +5035,7 @@ declare type InsightsMethodMap = InsightsMethodMap_2;
5035
5035
 
5036
5036
  declare type InsightsProps<TInsightsClient extends ProvidedInsightsClient = ProvidedInsightsClient> = {
5037
5037
  insightsClient?: TInsightsClient;
5038
- insightsInitParams?: Partial<InsightsMethodMap['init'][0]>;
5038
+ insightsInitParams?: Partial<InsightsMethodMap['init'][0][0]>;
5039
5039
  onEvent?: (event: InsightsEvent, insightsClient: TInsightsClient) => void;
5040
5040
  };
5041
5041
 
@@ -6334,7 +6334,7 @@ declare type QueueItem = QueueItemMap[keyof QueueItemMap];
6334
6334
  declare type QueueItemMap = {
6335
6335
  [MethodName in keyof InsightsMethodMap]: [
6336
6336
  methodName: MethodName,
6337
- ...args: InsightsMethodMap[MethodName]
6337
+ ...args: InsightsMethodMap[MethodName][0][0]
6338
6338
  ];
6339
6339
  };
6340
6340
 
@@ -7321,7 +7321,7 @@ declare type RendererOptions<TWidgetParams> = {
7321
7321
  };
7322
7322
 
7323
7323
  declare type RenderOptions = SharedRenderOptions & {
7324
- results: SearchResults;
7324
+ results: SearchResults | null;
7325
7325
  };
7326
7326
 
7327
7327
  declare type RenderState = {
@@ -7531,7 +7531,7 @@ declare namespace routers {
7531
7531
 
7532
7532
  declare type ScopedResult = {
7533
7533
  indexId: string;
7534
- results: SearchResults;
7534
+ results: SearchResults | null;
7535
7535
  helper: AlgoliaSearchHelper;
7536
7536
  };
7537
7537
 
@@ -8283,7 +8283,7 @@ declare type TrackedFilterRefinement = string | number | boolean;
8283
8283
  declare type TransformItems<TItem, TMetadata = TransformItemsMetadata> = (items: TItem[], metadata: TMetadata) => TItem[];
8284
8284
 
8285
8285
  declare type TransformItemsMetadata = {
8286
- results?: SearchResults;
8286
+ results: SearchResults | undefined | null;
8287
8287
  };
8288
8288
 
8289
8289
  declare type TransformSearchParameters = (searchParameters: SearchParameters) => PlainSearchParameters;