instantsearch.js 4.40.5 → 4.41.1

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ ## [4.41.1](https://github.com/algolia/instantsearch.js/compare/v4.41.0...v4.41.1) (2022-06-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **insights:** don't send view event if search is stalled ([#5058](https://github.com/algolia/instantsearch.js/issues/5058)) ([1686dfb](https://github.com/algolia/instantsearch.js/commit/1686dfb096cfce062e268feda7956e3b160bf2da)), closes [/github.com/algolia/instantsearch.js/blob/99f6fe1dc51e4815e5b9efcfb30e3e2f3127e763/src/lib/utils/createSendEventForHits.ts#L168](https://github.com//github.com/algolia/instantsearch.js/blob/99f6fe1dc51e4815e5b9efcfb30e3e2f3127e763/src/lib/utils/createSendEventForHits.ts/issues/L168) [/github.com/algolia/instantsearch.js/blob/55313e4ea4105b777f3f102e9f48a7e440496d25/src/middlewares/createInsightsMiddleware.ts#L144](https://github.com//github.com/algolia/instantsearch.js/blob/55313e4ea4105b777f3f102e9f48a7e440496d25/src/middlewares/createInsightsMiddleware.ts/issues/L144)
7
+ * **types:** avoid inferring UiState type from initialUiState ([#5061](https://github.com/algolia/instantsearch.js/issues/5061)) ([80ca07e](https://github.com/algolia/instantsearch.js/commit/80ca07e29064357343ee997be94ef10beadba637)), closes [/github.com/Microsoft/TypeScript/issues/14829#issuecomment-504042546](https://github.com//github.com/Microsoft/TypeScript/issues/14829/issues/issuecomment-504042546) [#5060](https://github.com/algolia/instantsearch.js/issues/5060)
8
+ * **types:** make all usages of UiState in InstantSearch generic ([#5060](https://github.com/algolia/instantsearch.js/issues/5060)) ([2b9e76b](https://github.com/algolia/instantsearch.js/commit/2b9e76b568fb4d4cc5bd49c384ee583d84d6f39a))
9
+
10
+
11
+
12
+ # [4.41.0](https://github.com/algolia/instantsearch.js/compare/v4.40.6...v4.41.0) (2022-06-01)
13
+
14
+
15
+ ### Features
16
+
17
+ * **core:** don't schedule search without widgets ([#5056](https://github.com/algolia/instantsearch.js/issues/5056)) ([ea3d6d9](https://github.com/algolia/instantsearch.js/commit/ea3d6d9c6ae1fe2f90bf5643d4bdcbb89507e9bc))
18
+
19
+
20
+
21
+ ## [4.40.6](https://github.com/algolia/instantsearch.js/compare/v4.40.5...v4.40.6) (2022-05-24)
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * **types:** only allow `null` for parent in `getWidgetRenderState` if widget is an index ([#5052](https://github.com/algolia/instantsearch.js/issues/5052)) ([fe0fce0](https://github.com/algolia/instantsearch.js/commit/fe0fce0641ffff9af1d1303b7ee71d77ba08f8bd))
27
+
28
+
29
+
1
30
  ## [4.40.5](https://github.com/algolia/instantsearch.js/compare/v4.40.4...v4.40.5) (2022-04-26)
2
31
 
3
32
 
@@ -61,10 +61,9 @@ var withUsage = (0, _index2.createDocumentationMessageGenerator)({
61
61
 
62
62
  function defaultCreateURL() {
63
63
  return '#';
64
- }
65
- /**
66
- * Global options for an InstantSearch instance.
67
- */
64
+ } // this purposely breaks typescript's type inference to ensure it's not used
65
+ // as it's used for a default parameter for example
66
+ // source: https://github.com/Microsoft/TypeScript/issues/14829#issuecomment-504042546
68
67
 
69
68
 
70
69
  /**
@@ -481,9 +480,17 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
481
480
  (0, _index2.defer)(function () {
482
481
  _this3.scheduleSearch = originalScheduleSearch;
483
482
  })();
484
- } else {
485
- this.scheduleSearch();
486
- } // Keep the previous reference for legacy purpose, some pattern use
483
+ } // We only schedule a search when widgets have been added before `start()`
484
+ // because there are listeners that can use these results.
485
+ // This is especially useful in framework-based flavors that wait for
486
+ // dynamically-added widgets to trigger a network request. It avoids
487
+ // having to batch this initial network request with the one coming from
488
+ // `addWidgets()`.
489
+ // Later, we could also skip `index()` widgets and widgets that don't read
490
+ // the results, but this is an optimization that has a very low impact for now.
491
+ else if (this.mainIndex.getWidgets().length > 0) {
492
+ this.scheduleSearch();
493
+ } // Keep the previous reference for legacy purpose, some pattern use
487
494
  // the direct Helper access `search.helper` (e.g multi-index).
488
495
 
489
496
 
@@ -25,7 +25,8 @@ var buildPayloads = function buildPayloads(_ref) {
25
25
  var index = _ref.index,
26
26
  widgetType = _ref.widgetType,
27
27
  methodName = _ref.methodName,
28
- args = _ref.args;
28
+ args = _ref.args,
29
+ isSearchStalled = _ref.isSearchStalled;
29
30
 
30
31
  // when there's only one argument, that means it's custom
31
32
  if (args.length === 1 && _typeof(args[0]) === 'object') {
@@ -72,6 +73,10 @@ var buildPayloads = function buildPayloads(_ref) {
72
73
  });
73
74
 
74
75
  if (eventType === 'view') {
76
+ if (isSearchStalled) {
77
+ return [];
78
+ }
79
+
75
80
  return hitsChunks.map(function (batch, i) {
76
81
  return {
77
82
  insightsMethod: 'viewedObjectIDs',
@@ -142,7 +147,8 @@ function createSendEventForHits(_ref2) {
142
147
  widgetType: widgetType,
143
148
  index: index,
144
149
  methodName: 'sendEvent',
145
- args: args
150
+ args: args,
151
+ isSearchStalled: instantSearchInstance._isSearchStalled
146
152
  });
147
153
  payloads.forEach(function (payload) {
148
154
  return instantSearchInstance.sendEventToInsights(payload);
@@ -165,7 +171,8 @@ function createBindEventForHits(_ref3) {
165
171
  widgetType: widgetType,
166
172
  index: index,
167
173
  methodName: 'bindEvent',
168
- args: args
174
+ args: args,
175
+ isSearchStalled: false
169
176
  });
170
177
  return payloads.length ? "data-insights-event=".concat((0, _serializer.serializePayload)(payloads)) : '';
171
178
  };
@@ -8,7 +8,7 @@ exports.safelyRunOnBrowser = safelyRunOnBrowser;
8
8
  // eslint-disable-next-line no-restricted-globals
9
9
 
10
10
  /**
11
- * Runs code on browser enviromnents safely.
11
+ * Runs code on browser environments safely.
12
12
  */
13
13
  function safelyRunOnBrowser(callback) {
14
14
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '4.40.5';
7
+ var _default = '4.41.1';
8
8
  exports.default = _default;
@@ -2003,9 +2003,15 @@ declare type HTMLMarkerArguments = {
2003
2003
 
2004
2004
  declare const index: (widgetParams: IndexWidgetParams) => IndexWidget;
2005
2005
 
2006
- declare type IndexInitOptions = Pick<InitOptions, 'instantSearchInstance' | 'parent' | 'uiState'>;
2006
+ declare type IndexInitOptions = {
2007
+ instantSearchInstance: InstantSearch;
2008
+ parent: IndexWidget | null;
2009
+ uiState: UiState;
2010
+ };
2007
2011
 
2008
- declare type IndexRenderOptions = Pick<RenderOptions, 'instantSearchInstance'>;
2012
+ declare type IndexRenderOptions = {
2013
+ instantSearchInstance: InstantSearch;
2014
+ };
2009
2015
 
2010
2016
  declare type IndexRenderState = Partial<ConnectorRenderStates & WidgetRenderStates>;
2011
2017
 
@@ -2280,7 +2286,7 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
2280
2286
  client: InstantSearchOptions['searchClient'];
2281
2287
  indexName: string;
2282
2288
  insightsClient: InsightsClient | null;
2283
- onStateChange: InstantSearchOptions['onStateChange'] | null;
2289
+ onStateChange: InstantSearchOptions<TUiState>['onStateChange'] | null;
2284
2290
  helper: AlgoliaSearchHelper | null;
2285
2291
  mainHelper: AlgoliaSearchHelper | null;
2286
2292
  mainIndex: IndexWidget;
@@ -2290,9 +2296,9 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
2290
2296
  _stalledSearchDelay: number;
2291
2297
  _searchStalledTimer: any;
2292
2298
  _isSearchStalled: boolean;
2293
- _initialUiState: UiState;
2299
+ _initialUiState: TUiState;
2294
2300
  _initialResults: InitialResults | null;
2295
- _createURL: CreateURL<UiState>;
2301
+ _createURL: CreateURL<TUiState>;
2296
2302
  _searchFunction?: InstantSearchOptions['searchFunction'];
2297
2303
  _mainHelperSearch?: AlgoliaSearchHelper['search'];
2298
2304
  middleware: Array<{
@@ -2362,13 +2368,13 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
2362
2368
  cancel(): void;
2363
2369
  };
2364
2370
  scheduleStalledRender(): void;
2365
- setUiState(uiState: UiState | ((previousUiState: UiState) => UiState)): void;
2366
- getUiState(): UiState;
2371
+ setUiState(uiState: TUiState | ((previousUiState: TUiState) => TUiState)): void;
2372
+ getUiState(): TUiState;
2367
2373
  onInternalStateChange: ((...args: any[]) => void) & {
2368
2374
  wait(): Promise<void>;
2369
2375
  cancel(): void;
2370
2376
  };
2371
- createURL(nextState?: UiState): string;
2377
+ createURL(nextState?: TUiState): string;
2372
2378
  refresh(): void;
2373
2379
  }
2374
2380
 
@@ -2460,8 +2466,8 @@ declare type InstantSearchOptions<TUiState extends UiState = UiState, TRouteStat
2460
2466
  * become in charge of updating the UI state with the `setUiState` function.
2461
2467
  */
2462
2468
  onStateChange?: (params: {
2463
- uiState: UiState;
2464
- setUiState(uiState: UiState | ((previousUiState: UiState) => UiState)): void;
2469
+ uiState: TUiState;
2470
+ setUiState(uiState: TUiState | ((previousUiState: TUiState) => TUiState)): void;
2465
2471
  }) => void;
2466
2472
  /**
2467
2473
  * Injects a `uiState` to the `instantsearch` instance. You can use this option
@@ -2469,7 +2475,7 @@ declare type InstantSearchOptions<TUiState extends UiState = UiState, TRouteStat
2469
2475
  * for the first search. To unconditionally pass additional parameters to the
2470
2476
  * Algolia API, take a look at the `configure` widget.
2471
2477
  */
2472
- initialUiState?: TUiState;
2478
+ initialUiState?: NoInfer<TUiState>;
2473
2479
  /**
2474
2480
  * Time before a search is considered stalled. The default is 200ms
2475
2481
  */
@@ -2773,6 +2779,8 @@ declare namespace middlewares {
2773
2779
  }
2774
2780
  }
2775
2781
 
2782
+ declare type NoInfer<T> = [T][T extends any ? 0 : never];
2783
+
2776
2784
  declare const numericMenu: NumericMenuWidget;
2777
2785
 
2778
2786
  declare type NumericMenuComponentCSSClasses = ComponentCSSClasses<NumericMenuCSSClasses>;
@@ -4595,7 +4603,7 @@ declare type SendEventForToggle = BuiltInSendEventForToggle & CustomSendEventFor
4595
4603
 
4596
4604
  declare type SharedRenderOptions = {
4597
4605
  instantSearchInstance: InstantSearch;
4598
- parent: IndexWidget | null;
4606
+ parent: IndexWidget;
4599
4607
  templatesConfig: Record<string, unknown>;
4600
4608
  scopedResults: ScopedResult[];
4601
4609
  state: SearchParameters;
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.40.5 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.41.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -7692,7 +7692,8 @@
7692
7692
  var index = _ref.index,
7693
7693
  widgetType = _ref.widgetType,
7694
7694
  methodName = _ref.methodName,
7695
- args = _ref.args;
7695
+ args = _ref.args,
7696
+ isSearchStalled = _ref.isSearchStalled;
7696
7697
 
7697
7698
  // when there's only one argument, that means it's custom
7698
7699
  if (args.length === 1 && _typeof(args[0]) === 'object') {
@@ -7735,6 +7736,10 @@
7735
7736
  });
7736
7737
 
7737
7738
  if (eventType === 'view') {
7739
+ if (isSearchStalled) {
7740
+ return [];
7741
+ }
7742
+
7738
7743
  return hitsChunks.map(function (batch, i) {
7739
7744
  return {
7740
7745
  insightsMethod: 'viewedObjectIDs',
@@ -7803,7 +7808,8 @@
7803
7808
  widgetType: widgetType,
7804
7809
  index: index,
7805
7810
  methodName: 'sendEvent',
7806
- args: args
7811
+ args: args,
7812
+ isSearchStalled: instantSearchInstance._isSearchStalled
7807
7813
  });
7808
7814
  payloads.forEach(function (payload) {
7809
7815
  return instantSearchInstance.sendEventToInsights(payload);
@@ -7825,7 +7831,8 @@
7825
7831
  widgetType: widgetType,
7826
7832
  index: index,
7827
7833
  methodName: 'bindEvent',
7828
- args: args
7834
+ args: args,
7835
+ isSearchStalled: false
7829
7836
  });
7830
7837
  return payloads.length ? "data-insights-event=".concat(serializePayload(payloads)) : '';
7831
7838
  };
@@ -7965,7 +7972,7 @@
7965
7972
  // eslint-disable-next-line no-restricted-globals
7966
7973
 
7967
7974
  /**
7968
- * Runs code on browser enviromnents safely.
7975
+ * Runs code on browser environments safely.
7969
7976
  */
7970
7977
  function safelyRunOnBrowser(callback) {
7971
7978
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
@@ -8536,7 +8543,7 @@
8536
8543
  instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
8537
8544
  }
8538
8545
 
8539
- var version$1 = '4.40.5';
8546
+ var version$1 = '4.41.1';
8540
8547
 
8541
8548
  var NAMESPACE = 'ais';
8542
8549
  var component = function component(componentName) {
@@ -10026,10 +10033,9 @@
10026
10033
 
10027
10034
  function defaultCreateURL() {
10028
10035
  return '#';
10029
- }
10030
- /**
10031
- * Global options for an InstantSearch instance.
10032
- */
10036
+ } // this purposely breaks typescript's type inference to ensure it's not used
10037
+ // as it's used for a default parameter for example
10038
+ // source: https://github.com/Microsoft/TypeScript/issues/14829#issuecomment-504042546
10033
10039
 
10034
10040
 
10035
10041
  /**
@@ -10446,9 +10452,17 @@
10446
10452
  defer(function () {
10447
10453
  _this3.scheduleSearch = originalScheduleSearch;
10448
10454
  })();
10449
- } else {
10450
- this.scheduleSearch();
10451
- } // Keep the previous reference for legacy purpose, some pattern use
10455
+ } // We only schedule a search when widgets have been added before `start()`
10456
+ // because there are listeners that can use these results.
10457
+ // This is especially useful in framework-based flavors that wait for
10458
+ // dynamically-added widgets to trigger a network request. It avoids
10459
+ // having to batch this initial network request with the one coming from
10460
+ // `addWidgets()`.
10461
+ // Later, we could also skip `index()` widgets and widgets that don't read
10462
+ // the results, but this is an optimization that has a very low impact for now.
10463
+ else if (this.mainIndex.getWidgets().length > 0) {
10464
+ this.scheduleSearch();
10465
+ } // Keep the previous reference for legacy purpose, some pattern use
10452
10466
  // the direct Helper access `search.helper` (e.g multi-index).
10453
10467
 
10454
10468