instantsearch.js 4.32.0 → 4.33.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 (34) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/cjs/connectors/powered-by/connectPoweredBy.js +13 -4
  3. package/cjs/lib/InstantSearch.js +4 -2
  4. package/cjs/lib/infiniteHitsCache/sessionStorage.js +16 -12
  5. package/cjs/lib/routers/history.js +89 -42
  6. package/cjs/lib/utils/detect-insights-client.js +10 -1
  7. package/cjs/lib/utils/index.js +10 -1
  8. package/cjs/lib/utils/safelyRunOnBrowser.js +30 -0
  9. package/cjs/lib/version.js +1 -1
  10. package/cjs/lib/voiceSearchHelper/index.js +5 -0
  11. package/cjs/middlewares/createMetadataMiddleware.js +12 -3
  12. package/dist/instantsearch.development.d.ts +13 -2
  13. package/dist/instantsearch.development.js +161 -66
  14. package/dist/instantsearch.development.js.map +1 -1
  15. package/dist/instantsearch.development.min.d.ts +13 -2
  16. package/dist/instantsearch.production.d.ts +13 -2
  17. package/dist/instantsearch.production.min.d.ts +13 -2
  18. package/dist/instantsearch.production.min.js +2 -2
  19. package/dist/instantsearch.production.min.js.map +1 -1
  20. package/es/connectors/powered-by/connectPoweredBy.js +14 -5
  21. package/es/lib/InstantSearch.js +4 -2
  22. package/es/lib/infiniteHitsCache/sessionStorage.js +17 -14
  23. package/es/lib/routers/history.d.ts +13 -2
  24. package/es/lib/routers/history.js +88 -42
  25. package/es/lib/utils/detect-insights-client.js +9 -1
  26. package/es/lib/utils/index.d.ts +1 -0
  27. package/es/lib/utils/index.js +2 -1
  28. package/es/lib/utils/safelyRunOnBrowser.d.ts +14 -0
  29. package/es/lib/utils/safelyRunOnBrowser.js +23 -0
  30. package/es/lib/version.d.ts +1 -1
  31. package/es/lib/version.js +1 -1
  32. package/es/lib/voiceSearchHelper/index.js +5 -0
  33. package/es/middlewares/createMetadataMiddleware.js +12 -3
  34. package/package.json +2 -2
@@ -455,13 +455,23 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
455
455
  * It should be symmetrical to `createURL`.
456
456
  */
457
457
  private readonly parseURL;
458
+ /**
459
+ * Returns the location to store in the history.
460
+ * @default () => window.location
461
+ */
462
+ private readonly getLocation;
458
463
  private writeTimer?;
459
464
  private _onPopState;
465
+ /**
466
+ * Indicates if history.pushState should be executed.
467
+ * It needs to avoid pushing state to history in case of back/forward in browser
468
+ */
469
+ private shouldPushState;
460
470
  /**
461
471
  * Initializes a new storage provider that syncs the search state to the URL
462
472
  * using web APIs (`window.location.pushState` and `onpopstate` event).
463
473
  */
464
- constructor({ windowTitle, writeDelay, createURL, parseURL, }: BrowserHistoryArgs<TRouteState>);
474
+ constructor({ windowTitle, writeDelay, createURL, parseURL, getLocation, }: BrowserHistoryArgs<TRouteState>);
465
475
  /**
466
476
  * Reads the URL and returns a syncable UI search state.
467
477
  */
@@ -494,6 +504,7 @@ declare type BrowserHistoryArgs<TRouteState> = {
494
504
  writeDelay: number;
495
505
  createURL: CreateURL_2<TRouteState>;
496
506
  parseURL: ParseURL<TRouteState>;
507
+ getLocation(): Location;
497
508
  };
498
509
 
499
510
  declare type BuiltInBindEventForHits = (eventType: string, hits: Hit | Hits, eventName?: string) => string;
@@ -1723,7 +1734,7 @@ declare type HighlightOptions = {
1723
1734
  }>;
1724
1735
  };
1725
1736
 
1726
- declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1737
+ declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1727
1738
 
1728
1739
  declare type Hit = {
1729
1740
  __position: number;
@@ -455,13 +455,23 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
455
455
  * It should be symmetrical to `createURL`.
456
456
  */
457
457
  private readonly parseURL;
458
+ /**
459
+ * Returns the location to store in the history.
460
+ * @default () => window.location
461
+ */
462
+ private readonly getLocation;
458
463
  private writeTimer?;
459
464
  private _onPopState;
465
+ /**
466
+ * Indicates if history.pushState should be executed.
467
+ * It needs to avoid pushing state to history in case of back/forward in browser
468
+ */
469
+ private shouldPushState;
460
470
  /**
461
471
  * Initializes a new storage provider that syncs the search state to the URL
462
472
  * using web APIs (`window.location.pushState` and `onpopstate` event).
463
473
  */
464
- constructor({ windowTitle, writeDelay, createURL, parseURL, }: BrowserHistoryArgs<TRouteState>);
474
+ constructor({ windowTitle, writeDelay, createURL, parseURL, getLocation, }: BrowserHistoryArgs<TRouteState>);
465
475
  /**
466
476
  * Reads the URL and returns a syncable UI search state.
467
477
  */
@@ -494,6 +504,7 @@ declare type BrowserHistoryArgs<TRouteState> = {
494
504
  writeDelay: number;
495
505
  createURL: CreateURL_2<TRouteState>;
496
506
  parseURL: ParseURL<TRouteState>;
507
+ getLocation(): Location;
497
508
  };
498
509
 
499
510
  declare type BuiltInBindEventForHits = (eventType: string, hits: Hit | Hits, eventName?: string) => string;
@@ -1723,7 +1734,7 @@ declare type HighlightOptions = {
1723
1734
  }>;
1724
1735
  };
1725
1736
 
1726
- declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1737
+ declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1727
1738
 
1728
1739
  declare type Hit = {
1729
1740
  __position: number;
@@ -455,13 +455,23 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
455
455
  * It should be symmetrical to `createURL`.
456
456
  */
457
457
  private readonly parseURL;
458
+ /**
459
+ * Returns the location to store in the history.
460
+ * @default () => window.location
461
+ */
462
+ private readonly getLocation;
458
463
  private writeTimer?;
459
464
  private _onPopState;
465
+ /**
466
+ * Indicates if history.pushState should be executed.
467
+ * It needs to avoid pushing state to history in case of back/forward in browser
468
+ */
469
+ private shouldPushState;
460
470
  /**
461
471
  * Initializes a new storage provider that syncs the search state to the URL
462
472
  * using web APIs (`window.location.pushState` and `onpopstate` event).
463
473
  */
464
- constructor({ windowTitle, writeDelay, createURL, parseURL, }: BrowserHistoryArgs<TRouteState>);
474
+ constructor({ windowTitle, writeDelay, createURL, parseURL, getLocation, }: BrowserHistoryArgs<TRouteState>);
465
475
  /**
466
476
  * Reads the URL and returns a syncable UI search state.
467
477
  */
@@ -494,6 +504,7 @@ declare type BrowserHistoryArgs<TRouteState> = {
494
504
  writeDelay: number;
495
505
  createURL: CreateURL_2<TRouteState>;
496
506
  parseURL: ParseURL<TRouteState>;
507
+ getLocation(): Location;
497
508
  };
498
509
 
499
510
  declare type BuiltInBindEventForHits = (eventType: string, hits: Hit | Hits, eventName?: string) => string;
@@ -1723,7 +1734,7 @@ declare type HighlightOptions = {
1723
1734
  }>;
1724
1735
  };
1725
1736
 
1726
- declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1737
+ declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1727
1738
 
1728
1739
  declare type Hit = {
1729
1740
  __position: number;