instantsearch.js 4.33.1 → 4.36.0

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 (41) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +24 -1
  3. package/cjs/connectors/autocomplete/connectAutocomplete.js +2 -1
  4. package/cjs/connectors/dynamic-widgets/connectDynamicWidgets.js +30 -5
  5. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +1 -1
  6. package/cjs/connectors/numeric-menu/connectNumericMenu.js +6 -4
  7. package/cjs/connectors/pagination/connectPagination.js +3 -3
  8. package/cjs/connectors/search-box/connectSearchBox.js +4 -3
  9. package/cjs/connectors/sort-by/connectSortBy.js +2 -1
  10. package/cjs/connectors/stats/connectStats.js +4 -4
  11. package/cjs/connectors/toggle-refinement/connectToggleRefinement.js +1 -1
  12. package/cjs/lib/InstantSearch.js +23 -2
  13. package/cjs/lib/version.js +1 -1
  14. package/cjs/widgets/dynamic-widgets/dynamic-widgets.js +8 -5
  15. package/cjs/widgets/index/index.js +20 -2
  16. package/dist/instantsearch.development.d.ts +23 -2
  17. package/dist/instantsearch.development.js +105 -37
  18. package/dist/instantsearch.development.js.map +1 -1
  19. package/dist/instantsearch.development.min.d.ts +23 -2
  20. package/dist/instantsearch.production.d.ts +23 -2
  21. package/dist/instantsearch.production.min.d.ts +23 -2
  22. package/dist/instantsearch.production.min.js +2 -2
  23. package/dist/instantsearch.production.min.js.map +1 -1
  24. package/es/connectors/autocomplete/connectAutocomplete.js +2 -1
  25. package/es/connectors/dynamic-widgets/connectDynamicWidgets.d.ts +14 -0
  26. package/es/connectors/dynamic-widgets/connectDynamicWidgets.js +31 -6
  27. package/es/connectors/infinite-hits/connectInfiniteHits.js +1 -1
  28. package/es/connectors/numeric-menu/connectNumericMenu.js +6 -4
  29. package/es/connectors/pagination/connectPagination.js +3 -3
  30. package/es/connectors/search-box/connectSearchBox.js +4 -3
  31. package/es/connectors/sort-by/connectSortBy.js +2 -1
  32. package/es/connectors/stats/connectStats.js +4 -4
  33. package/es/connectors/toggle-refinement/connectToggleRefinement.js +1 -1
  34. package/es/lib/InstantSearch.d.ts +3 -3
  35. package/es/lib/InstantSearch.js +23 -2
  36. package/es/lib/version.d.ts +1 -1
  37. package/es/lib/version.js +1 -1
  38. package/es/types/results.d.ts +7 -0
  39. package/es/widgets/dynamic-widgets/dynamic-widgets.js +8 -5
  40. package/es/widgets/index/index.js +20 -2
  41. package/package.json +10 -7
@@ -52,6 +52,7 @@ var connectAutocomplete = function connectAutocomplete(renderFn) {
52
52
  var _this = this;
53
53
 
54
54
  var helper = _ref4.helper,
55
+ state = _ref4.state,
55
56
  scopedResults = _ref4.scopedResults,
56
57
  instantSearchInstance = _ref4.instantSearchInstance;
57
58
 
@@ -79,7 +80,7 @@ var connectAutocomplete = function connectAutocomplete(renderFn) {
79
80
  };
80
81
  });
81
82
  return {
82
- currentRefinement: helper.state.query || '',
83
+ currentRefinement: state.query || '',
83
84
  indices: indices,
84
85
  refine: connectorState.refine,
85
86
  widgetParams: widgetParams
@@ -23,6 +23,20 @@ export declare type DynamicWidgetsConnectorParams = {
23
23
  transformItems?(items: string[], metadata: {
24
24
  results: SearchResults;
25
25
  }): string[];
26
+ /**
27
+ * To prevent unneeded extra network requests when widgets mount or unmount,
28
+ * we request all facet values.
29
+ *
30
+ * @default ['*']
31
+ */
32
+ facets?: ['*'] | never[];
33
+ /**
34
+ * If you have more than 20 facet values pinned, you need to increase the
35
+ * maxValuesPerFacet to at least that value.
36
+ *
37
+ * @default 20
38
+ */
39
+ maxValuesPerFacet?: number;
26
40
  };
27
41
  export declare type DynamicWidgetsWidgetDescription = {
28
42
  $$type: 'ais.dynamicWidgets';
@@ -6,17 +6,22 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
 
7
7
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
8
8
 
9
- import { checkRendering, createDocumentationMessageGenerator, getWidgetAttribute, noop } from '../../lib/utils';
9
+ import { checkRendering, createDocumentationMessageGenerator, getWidgetAttribute, noop, warning } from '../../lib/utils';
10
10
  var withUsage = createDocumentationMessageGenerator({
11
11
  name: 'dynamic-widgets',
12
12
  connector: true
13
13
  });
14
+ var MAX_WILDCARD_FACETS = 20;
14
15
 
15
16
  var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
16
17
  var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
17
18
  checkRendering(renderFn, withUsage());
18
19
  return function (widgetParams) {
19
20
  var widgets = widgetParams.widgets,
21
+ _widgetParams$maxValu = widgetParams.maxValuesPerFacet,
22
+ maxValuesPerFacet = _widgetParams$maxValu === void 0 ? 20 : _widgetParams$maxValu,
23
+ _widgetParams$facets = widgetParams.facets,
24
+ facets = _widgetParams$facets === void 0 ? ['*'] : _widgetParams$facets,
20
25
  _widgetParams$transfo = widgetParams.transformItems,
21
26
  transformItems = _widgetParams$transfo === void 0 ? function (items) {
22
27
  return items;
@@ -29,6 +34,10 @@ var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
29
34
  throw new Error(withUsage('The `widgets` option expects an array of widgets.'));
30
35
  }
31
36
 
37
+ if (!(Array.isArray(facets) && facets.length <= 1 && (facets[0] === '*' || facets[0] === undefined))) {
38
+ throw new Error(withUsage("The `facets` option only accepts [] or [\"*\"], you passed ".concat(JSON.stringify(facets))));
39
+ }
40
+
32
41
  var localWidgets = new Map();
33
42
  return {
34
43
  $$type: 'ais.dynamicWidgets',
@@ -108,6 +117,14 @@ var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
108
117
  parent.removeWidgets(toRemove);
109
118
  unmountFn();
110
119
  },
120
+ getWidgetSearchParameters: function getWidgetSearchParameters(state) {
121
+ // broadening the scope of facets to avoid conflict between never and *
122
+ return facets.reduce(function (acc, curr) {
123
+ return acc.addFacet(curr);
124
+ }, state.setQueryParameters({
125
+ maxValuesPerFacet: Math.max(maxValuesPerFacet || 0, state.maxValuesPerFacet || 0)
126
+ }));
127
+ },
111
128
  getRenderState: function getRenderState(renderState, renderOptions) {
112
129
  return _objectSpread(_objectSpread({}, renderState), {}, {
113
130
  dynamicWidgets: this.getWidgetRenderState(renderOptions)
@@ -116,7 +133,8 @@ var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
116
133
  getWidgetRenderState: function getWidgetRenderState(_ref4) {
117
134
  var _results$renderingCon, _results$renderingCon2, _results$renderingCon3, _results$renderingCon4;
118
135
 
119
- var results = _ref4.results;
136
+ var results = _ref4.results,
137
+ state = _ref4.state;
120
138
 
121
139
  if (!results) {
122
140
  return {
@@ -125,11 +143,18 @@ var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
125
143
  };
126
144
  }
127
145
 
128
- var attributesToRender = (_results$renderingCon = (_results$renderingCon2 = results.renderingContent) === null || _results$renderingCon2 === void 0 ? void 0 : (_results$renderingCon3 = _results$renderingCon2.facetOrdering) === null || _results$renderingCon3 === void 0 ? void 0 : (_results$renderingCon4 = _results$renderingCon3.facets) === null || _results$renderingCon4 === void 0 ? void 0 : _results$renderingCon4.order) !== null && _results$renderingCon !== void 0 ? _results$renderingCon : [];
146
+ var attributesToRender = transformItems((_results$renderingCon = (_results$renderingCon2 = results.renderingContent) === null || _results$renderingCon2 === void 0 ? void 0 : (_results$renderingCon3 = _results$renderingCon2.facetOrdering) === null || _results$renderingCon3 === void 0 ? void 0 : (_results$renderingCon4 = _results$renderingCon3.facets) === null || _results$renderingCon4 === void 0 ? void 0 : _results$renderingCon4.order) !== null && _results$renderingCon !== void 0 ? _results$renderingCon : [], {
147
+ results: results
148
+ });
149
+
150
+ if (!Array.isArray(attributesToRender)) {
151
+ throw new Error(withUsage('The `transformItems` option expects a function that returns an Array.'));
152
+ }
153
+
154
+ process.env.NODE_ENV === 'development' ? warning(maxValuesPerFacet >= (state.maxValuesPerFacet || 0), "The maxValuesPerFacet set by dynamic widgets (".concat(maxValuesPerFacet, ") is smaller than one of the limits set by a widget (").concat(state.maxValuesPerFacet, "). This causes a mismatch in query parameters and thus an extra network request when that widget is mounted.")) : void 0;
155
+ process.env.NODE_ENV === 'development' ? warning(attributesToRender.length <= MAX_WILDCARD_FACETS || widgetParams.facets !== undefined, "More than ".concat(MAX_WILDCARD_FACETS, " facets are requested to be displayed without explicitly setting which facets to retrieve. This could have a performance impact. Set \"facets\" to [] to do two smaller network requests, or explicitly to ['*'] to avoid this warning.")) : void 0;
129
156
  return {
130
- attributesToRender: transformItems(attributesToRender, {
131
- results: results
132
- }),
157
+ attributesToRender: attributesToRender,
133
158
  widgetParams: widgetParams
134
159
  };
135
160
  }
@@ -165,7 +165,7 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
165
165
  index: helper.getIndex(),
166
166
  widgetType: this.$$type
167
167
  });
168
- isFirstPage = helper.state.page === undefined || getFirstReceivedPage(helper.state, cachedHits) === 0;
168
+ isFirstPage = state.page === undefined || getFirstReceivedPage(state, cachedHits) === 0;
169
169
  } else {
170
170
  var _state$page3 = state.page,
171
171
  _page = _state$page3 === void 0 ? 0 : _state$page3;
@@ -234,6 +234,8 @@ function isRefined(state, attribute, option) {
234
234
  if (option.start !== undefined && option.end !== undefined) {
235
235
  if (option.start === option.end) {
236
236
  return hasNumericRefinement(currentRefinements, '=', option.start);
237
+ } else {
238
+ return hasNumericRefinement(currentRefinements, '>=', option.start) && hasNumericRefinement(currentRefinements, '<=', option.end);
237
239
  }
238
240
  }
239
241
 
@@ -287,17 +289,17 @@ function getRefinedState(state, attribute, facetValue) {
287
289
  if (refinedOption.start !== undefined) {
288
290
  if (hasNumericRefinement(currentRefinements, '>=', refinedOption.start)) {
289
291
  resolvedState = resolvedState.removeNumericRefinement(attribute, '>=', refinedOption.start);
290
- } else {
291
- resolvedState = resolvedState.addNumericRefinement(attribute, '>=', refinedOption.start);
292
292
  }
293
+
294
+ resolvedState = resolvedState.addNumericRefinement(attribute, '>=', refinedOption.start);
293
295
  }
294
296
 
295
297
  if (refinedOption.end !== undefined) {
296
298
  if (hasNumericRefinement(currentRefinements, '<=', refinedOption.end)) {
297
299
  resolvedState = resolvedState.removeNumericRefinement(attribute, '<=', refinedOption.end);
298
- } else {
299
- resolvedState = resolvedState.addNumericRefinement(attribute, '<=', refinedOption.end);
300
300
  }
301
+
302
+ resolvedState = resolvedState.addNumericRefinement(attribute, '<=', refinedOption.end);
301
303
  }
302
304
 
303
305
  if (typeof resolvedState.page === 'number') {
@@ -78,6 +78,7 @@ var connectPagination = function connectPagination(renderFn) {
78
78
  getWidgetRenderState: function getWidgetRenderState(_ref6) {
79
79
  var results = _ref6.results,
80
80
  helper = _ref6.helper,
81
+ state = _ref6.state,
81
82
  createURL = _ref6.createURL;
82
83
 
83
84
  if (!connectorState.refine) {
@@ -88,14 +89,13 @@ var connectPagination = function connectPagination(renderFn) {
88
89
  }
89
90
 
90
91
  if (!connectorState.createURL) {
91
- connectorState.createURL = function (state) {
92
+ connectorState.createURL = function (helperState) {
92
93
  return function (page) {
93
- return createURL(state.setPage(page));
94
+ return createURL(helperState.setPage(page));
94
95
  };
95
96
  };
96
97
  }
97
98
 
98
- var state = helper.state;
99
99
  var page = state.page || 0;
100
100
  var nbPages = getMaxPage(results || {
101
101
  nbPages: 0
@@ -63,11 +63,12 @@ var connectSearchBox = function connectSearchBox(renderFn) {
63
63
  },
64
64
  getWidgetRenderState: function getWidgetRenderState(_ref3) {
65
65
  var helper = _ref3.helper,
66
- searchMetadata = _ref3.searchMetadata;
66
+ searchMetadata = _ref3.searchMetadata,
67
+ state = _ref3.state;
67
68
 
68
69
  if (!_refine) {
69
70
  var setQueryAndSearch = function setQueryAndSearch(query) {
70
- if (query !== helper.state.query) {
71
+ if (query !== state.query) {
71
72
  helper.setQuery(query).search();
72
73
  }
73
74
  };
@@ -84,7 +85,7 @@ var connectSearchBox = function connectSearchBox(renderFn) {
84
85
 
85
86
  _clear = clear(helper);
86
87
  return {
87
- query: helper.state.query || '',
88
+ query: state.query || '',
88
89
  refine: _refine,
89
90
  clear: _cachedClear,
90
91
  widgetParams: widgetParams,
@@ -64,6 +64,7 @@ var connectSortBy = function connectSortBy(renderFn) {
64
64
  getWidgetRenderState: function getWidgetRenderState(_ref3) {
65
65
  var results = _ref3.results,
66
66
  helper = _ref3.helper,
67
+ state = _ref3.state,
67
68
  parent = _ref3.parent;
68
69
 
69
70
  if (!connectorState.initialIndex && parent) {
@@ -77,7 +78,7 @@ var connectSortBy = function connectSortBy(renderFn) {
77
78
  }
78
79
 
79
80
  return {
80
- currentRefinement: helper.state.index,
81
+ currentRefinement: state.index,
81
82
  options: transformItems(items),
82
83
  refine: connectorState.setIndex,
83
84
  hasNoResults: results ? results.nbHits === 0 : true,
@@ -42,18 +42,18 @@ var connectStats = function connectStats(renderFn) {
42
42
  },
43
43
  getWidgetRenderState: function getWidgetRenderState(_ref) {
44
44
  var results = _ref.results,
45
- helper = _ref.helper;
45
+ state = _ref.state;
46
46
 
47
47
  if (!results) {
48
48
  return {
49
- hitsPerPage: helper.state.hitsPerPage,
49
+ hitsPerPage: state.hitsPerPage,
50
50
  nbHits: 0,
51
51
  nbSortedHits: undefined,
52
52
  areHitsSorted: false,
53
53
  nbPages: 0,
54
- page: helper.state.page || 0,
54
+ page: state.page || 0,
55
55
  processingTimeMS: -1,
56
- query: helper.state.query || '',
56
+ query: state.query || '',
57
57
  widgetParams: widgetParams
58
58
  };
59
59
  }
@@ -177,7 +177,7 @@ var connectToggleRefinement = function connectToggleRefinement(renderFn) {
177
177
  createURL = _ref6.createURL,
178
178
  instantSearchInstance = _ref6.instantSearchInstance;
179
179
  var isRefined = results ? on.every(function (v) {
180
- return helper.state.isDisjunctiveFacetRefined(attribute, v);
180
+ return state.isDisjunctiveFacetRefined(attribute, v);
181
181
  }) : on.every(function (v) {
182
182
  return state.isDisjunctiveFacetRefined(attribute, v);
183
183
  });
@@ -1,8 +1,7 @@
1
- /// <reference types="node" />
2
1
  import type { AlgoliaSearchHelper } from 'algoliasearch-helper';
3
- import EventEmitter from 'events';
2
+ import EventEmitter from '@algolia/events';
4
3
  import type { IndexWidget } from '../widgets/index/index';
5
- import type { InsightsClient as AlgoliaInsightsClient, SearchClient, Widget, UiState, CreateURL, Middleware, MiddlewareDefinition, RenderState } from '../types';
4
+ import type { InsightsClient as AlgoliaInsightsClient, SearchClient, Widget, UiState, CreateURL, Middleware, MiddlewareDefinition, RenderState, InitialResults } from '../types';
6
5
  import type { RouterProps } from '../middlewares/createRouterMiddleware';
7
6
  import type { InsightsEvent } from '../middlewares/createInsightsMiddleware';
8
7
  /**
@@ -106,6 +105,7 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
106
105
  _searchStalledTimer: any;
107
106
  _isSearchStalled: boolean;
108
107
  _initialUiState: UiState;
108
+ _initialResults: InitialResults | null;
109
109
  _createURL: CreateURL<UiState>;
110
110
  _searchFunction?: InstantSearchOptions['searchFunction'];
111
111
  _mainHelperSearch?: AlgoliaSearchHelper['search'];
@@ -27,7 +27,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
27
27
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
28
28
 
29
29
  import algoliasearchHelper from 'algoliasearch-helper';
30
- import EventEmitter from 'events';
30
+ import EventEmitter from '@algolia/events';
31
31
  import index, { isIndexWidget } from '../widgets/index/index';
32
32
  import version from './version';
33
33
  import createHelpers from './createHelpers';
@@ -91,6 +91,8 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
91
91
 
92
92
  _defineProperty(_assertThisInitialized(_this), "_initialUiState", void 0);
93
93
 
94
+ _defineProperty(_assertThisInitialized(_this), "_initialResults", void 0);
95
+
94
96
  _defineProperty(_assertThisInitialized(_this), "_createURL", void 0);
95
97
 
96
98
  _defineProperty(_assertThisInitialized(_this), "_searchFunction", void 0);
@@ -195,6 +197,7 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
195
197
  _this._isSearchStalled = false;
196
198
  _this._createURL = defaultCreateURL;
197
199
  _this._initialUiState = initialUiState;
200
+ _this._initialResults = null;
198
201
 
199
202
  if (searchFunction) {
200
203
  _this._searchFunction = searchFunction;
@@ -437,9 +440,27 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
437
440
  parent: null,
438
441
  uiState: this._initialUiState
439
442
  });
440
- this.scheduleSearch(); // Keep the previous reference for legacy purpose, some pattern use
443
+
444
+ if (this._initialResults) {
445
+ var originalScheduleSearch = this.scheduleSearch; // We don't schedule a first search when initial results are provided
446
+ // because we already have the results to render. This skips the initial
447
+ // network request on the browser on `start`.
448
+
449
+ this.scheduleSearch = defer(noop); // We also skip the initial network request when widgets are dynamically
450
+ // added in the first tick (that's the case in all the framework-based flavors).
451
+ // When we add a widget to `index`, it calls `scheduleSearch`. We can rely
452
+ // on our `defer` util to restore the original `scheduleSearch` value once
453
+ // widgets are added to hook back to the regular lifecycle.
454
+
455
+ defer(function () {
456
+ _this3.scheduleSearch = originalScheduleSearch;
457
+ })();
458
+ } else {
459
+ this.scheduleSearch();
460
+ } // Keep the previous reference for legacy purpose, some pattern use
441
461
  // the direct Helper access `search.helper` (e.g multi-index).
442
462
 
463
+
443
464
  this.helper = this.mainIndex.getHelper(); // track we started the search if we add more widgets,
444
465
  // to init them directly after add
445
466
 
@@ -1,2 +1,2 @@
1
- declare const _default: "4.33.1";
1
+ declare const _default: "4.36.0";
2
2
  export default _default;
package/es/lib/version.js CHANGED
@@ -1 +1 @@
1
- export default '4.33.1';
1
+ export default '4.36.0';
@@ -1,3 +1,4 @@
1
+ import type { PlainSearchParameters, SearchResults } from 'algoliasearch-helper';
1
2
  export declare type HitAttributeHighlightResult = {
2
3
  value: string;
3
4
  matchLevel: 'none' | 'partial' | 'full';
@@ -64,3 +65,9 @@ export declare type NumericRefinement = {
64
65
  operator: string;
65
66
  };
66
67
  export declare type Refinement = FacetRefinement | NumericRefinement;
68
+ declare type InitialResult = {
69
+ state: PlainSearchParameters;
70
+ results: SearchResults['_rawResults'];
71
+ };
72
+ export declare type InitialResults = Record<string, InitialResult>;
73
+ export {};
@@ -4,6 +4,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
8
+
9
+ 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; }
10
+
7
11
  import connectDynamicWidgets from '../../connectors/dynamic-widgets/connectDynamicWidgets';
8
12
  import { component } from '../../lib/suit';
9
13
  import { createDocumentationMessageGenerator, getContainerNode, getWidgetAttribute } from '../../lib/utils';
@@ -24,9 +28,9 @@ function createContainer(rootContainer) {
24
28
  var dynamicWidgets = function dynamicWidgets(widgetParams) {
25
29
  var _ref = widgetParams || {},
26
30
  containerSelector = _ref.container,
27
- transformItems = _ref.transformItems,
28
31
  widgets = _ref.widgets,
29
- fallbackWidget = _ref.fallbackWidget;
32
+ fallbackWidget = _ref.fallbackWidget,
33
+ otherWidgetParams = _objectWithoutProperties(_ref, ["container", "widgets", "fallbackWidget"]);
30
34
 
31
35
  if (!containerSelector) {
32
36
  throw new Error(withUsage('The `container` option is required.'));
@@ -61,8 +65,7 @@ var dynamicWidgets = function dynamicWidgets(widgetParams) {
61
65
  }, function () {
62
66
  userContainer.removeChild(rootContainer);
63
67
  });
64
- var widget = makeWidget({
65
- transformItems: transformItems,
68
+ var widget = makeWidget(_objectSpread(_objectSpread({}, otherWidgetParams), {}, {
66
69
  widgets: connectorWidgets,
67
70
  fallbackWidget: typeof fallbackWidget === 'function' ? function (_ref3) {
68
71
  var attribute = _ref3.attribute;
@@ -73,7 +76,7 @@ var dynamicWidgets = function dynamicWidgets(widgetParams) {
73
76
  container: container
74
77
  });
75
78
  } : undefined
76
- });
79
+ }));
77
80
  return _objectSpread(_objectSpread({}, widget), {}, {
78
81
  init: function init(initOptions) {
79
82
  widgets.forEach(function (cb) {
@@ -275,7 +275,8 @@ var index = function index(widgetParams) {
275
275
  return this;
276
276
  },
277
277
  init: function init(_ref2) {
278
- var _this3 = this;
278
+ var _this3 = this,
279
+ _instantSearchInstanc;
279
280
 
280
281
  var instantSearchInstance = _ref2.instantSearchInstance,
281
282
  parent = _ref2.parent,
@@ -333,11 +334,21 @@ var index = function index(widgetParams) {
333
334
 
334
335
  derivedHelper = mainHelper.derive(function () {
335
336
  return mergeSearchParameters.apply(void 0, _toConsumableArray(resolveSearchParameters(_this3)));
336
- }); // Subscribe to the Helper state changes for the page before widgets
337
+ });
338
+ var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
339
+
340
+ if (indexInitialResults) {
341
+ // We restore the shape of the results provided to the instance to respect
342
+ // the helper's structure.
343
+ var results = new algoliasearchHelper.SearchResults(new algoliasearchHelper.SearchParameters(indexInitialResults.state), indexInitialResults.results);
344
+ derivedHelper.lastResults = results;
345
+ helper.lastResults = results;
346
+ } // Subscribe to the Helper state changes for the page before widgets
337
347
  // are initialized. This behavior mimics the original one of the Helper.
338
348
  // It makes sense to replicate it at the `init` step. We have another
339
349
  // listener on `change` below, once `init` is done.
340
350
 
351
+
341
352
  helper.on('change', function (_ref3) {
342
353
  var isPageReset = _ref3.isPageReset;
343
354
 
@@ -438,6 +449,13 @@ var index = function index(widgetParams) {
438
449
  instantSearchInstance.onInternalStateChange();
439
450
  }
440
451
  });
452
+
453
+ if (indexInitialResults) {
454
+ // If there are initial results, we're not notified of the next results
455
+ // because we don't trigger an initial search. We therefore need to directly
456
+ // schedule a render that will render the results injected on the helper.
457
+ instantSearchInstance.scheduleRender();
458
+ }
441
459
  },
442
460
  render: function render(_ref5) {
443
461
  var _this4 = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch.js",
3
- "version": "4.33.1",
3
+ "version": "4.36.0",
4
4
  "description": "InstantSearch.js is a JavaScript library for building performant and instant search experiences with Algolia.",
5
5
  "homepage": "https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/",
6
6
  "types": "es/index.d.ts",
@@ -55,16 +55,16 @@
55
55
  "@types/google.maps": "^3.45.3",
56
56
  "@types/hogan.js": "^3.0.0",
57
57
  "@types/qs": "^6.5.3",
58
- "algoliasearch-helper": "^3.6.2",
58
+ "algoliasearch-helper": "^3.7.0",
59
59
  "classnames": "^2.2.5",
60
- "events": "^1.1.0",
60
+ "@algolia/events": "^4.0.1",
61
61
  "hogan.js": "^3.0.2",
62
62
  "preact": "^10.0.0",
63
63
  "qs": "^6.5.1 < 6.10",
64
- "search-insights": "^2.0.5"
64
+ "search-insights": "^2.1.0"
65
65
  },
66
66
  "devDependencies": {
67
- "@algolia/client-search": "4.10.3",
67
+ "@algolia/client-search": "4.11.0",
68
68
  "@babel/cli": "7.8.4",
69
69
  "@babel/core": "7.9.6",
70
70
  "@babel/plugin-proposal-class-properties": "7.8.3",
@@ -95,7 +95,7 @@
95
95
  "@wdio/selenium-standalone-service": "5.16.5",
96
96
  "@wdio/spec-reporter": "5.16.5",
97
97
  "@wdio/static-server-service": "5.16.5",
98
- "algoliasearch": "4.10.3",
98
+ "algoliasearch": "4.11.0",
99
99
  "algoliasearch-v3": "npm:algoliasearch@3.35.1",
100
100
  "babel-eslint": "10.0.3",
101
101
  "babel-jest": "27.1.0",
@@ -144,13 +144,16 @@
144
144
  "typescript": "4.3.5",
145
145
  "webpack": "4.41.5"
146
146
  },
147
+ "peerDependencies": {
148
+ "algoliasearch": ">= 3.1 < 5"
149
+ },
147
150
  "resolutions": {
148
151
  "places.js/algoliasearch": "3.35.0"
149
152
  },
150
153
  "bundlesize": [
151
154
  {
152
155
  "path": "./dist/instantsearch.production.min.js",
153
- "maxSize": "69.25 kB"
156
+ "maxSize": "69.50 kB"
154
157
  },
155
158
  {
156
159
  "path": "./dist/instantsearch.development.js",