react-instantsearch 7.36.0 → 7.37.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.
@@ -65,11 +65,14 @@ var AutocompleteDetachedSearchButton = (0, _instantsearchuicomponents.createAuto
65
65
  Fragment: _react.Fragment
66
66
  });
67
67
  var id = 0;
68
- var useAutocompleteInstanceId = _react.default.useId ? function() {
69
- return _react.default.useId().replace(/:/g, '');
68
+ // Colons (`:r0:`) preserved so concatenations like `autocomplete:r0:input`
69
+ // have a recognisable boundary; callers that need a colon-free variant for
70
+ // InstantSearch's `indexId` strip them at the use site.
71
+ var useAutocompleteId = _react.default.useId ? function() {
72
+ return _react.default.useId();
70
73
  } : function() {
71
74
  return _react.default.useState(function() {
72
- return "a".concat(id++);
75
+ return ":a".concat(id++, ":");
73
76
  })[0];
74
77
  };
75
78
  var usePropGetters = (0, _instantsearchuicomponents.createAutocompletePropGetters)({
@@ -221,6 +224,10 @@ function EXPERIMENTAL_Autocomplete(props) {
221
224
  "translations",
222
225
  "transformItems"
223
226
  ]);
227
+ var autoFocus = restProps.autoFocus, placeholder = restProps.placeholder, classNames = restProps.classNames;
228
+ // Eager-mount only when `autoFocus` is set — otherwise wait for first focus
229
+ // before registering the autocomplete subtree in the search graph.
230
+ var _useState = _sliced_to_array._((0, _react.useState)(autoFocus === true), 2), activated = _useState[0], setActivated = _useState[1];
224
231
  var translations = _object_spread._({}, DEFAULT_TRANSLATIONS, userTranslations);
225
232
  var _useInstantSearch = (0, _reactinstantsearchcore.useInstantSearch)(), indexUiState = _useInstantSearch.indexUiState, indexRenderState = _useInstantSearch.indexRenderState, status = _useInstantSearch.status;
226
233
  var compositionID = (0, _reactinstantsearchcore.useInstantSearchContext)().compositionID;
@@ -230,9 +237,8 @@ function EXPERIMENTAL_Autocomplete(props) {
230
237
  }, props.aiMode ? {
231
238
  opensChat: true
232
239
  } : {})).refine;
233
- // In feeds-mode, indexId disambiguates multiple Autocomplete instances
234
- // sharing the same compositionID. Mirrors the fallback at line 111 for React <18.
235
- var instanceKey = useAutocompleteInstanceId();
240
+ var domId = useAutocompleteId();
241
+ var instanceKey = domId.replace(/:/g, '');
236
242
  if (isFeedsMode && indices !== undefined) {
237
243
  throw new Error('EXPERIMENTAL_Autocomplete: `feeds` and `indices` are mutually exclusive.');
238
244
  }
@@ -402,7 +408,84 @@ function EXPERIMENTAL_Autocomplete(props) {
402
408
  "indices",
403
409
  "feeds"
404
410
  ]);
411
+ var instance = (0, _reactinstantsearchcore.useInstantSearchContext)();
412
+ var detached = useDetachedMode(detachedMediaQuery);
413
+ var isDetached = detached.isDetached, setIsModalOpen = detached.setIsModalOpen;
414
+ // Lazy activation only: when `activated` flips from false to true, the
415
+ // newly-mounted isolated `<Index>` schedules the parent's search even
416
+ // though the parent's state hasn't changed. Cancel it so only the
417
+ // autocomplete's own search fires on activation. Skip when `autoFocus`
418
+ // mounts the inner eagerly — the parent's legitimate initial search
419
+ // shares the same defer slot and must not be cancelled.
420
+ var initialActivatedRef = (0, _react.useRef)(activated);
421
+ (0, _react.useLayoutEffect)(function() {
422
+ if (activated && !initialActivatedRef.current) {
423
+ initialActivatedRef.current = true;
424
+ instance.scheduleSearch.cancel();
425
+ }
426
+ }, [
427
+ activated,
428
+ instance
429
+ ]);
430
+ if (!activated) {
431
+ var _indexUiState_query, _indexUiState_query1;
432
+ restProps.indices; restProps.feeds; restProps.autoFocus; restProps.placeholder; restProps.classNames; restProps.aiMode; restProps.panelComponent; restProps.getSearchPageURL; restProps.onSelect; var shellRootProps = _object_without_properties._(restProps, [
433
+ "indices",
434
+ "feeds",
435
+ "autoFocus",
436
+ "placeholder",
437
+ "classNames",
438
+ "aiMode",
439
+ "panelComponent",
440
+ "getSearchPageURL",
441
+ "onSelect"
442
+ ]);
443
+ var activateWithQueryMirror = function activateWithQueryMirror() {
444
+ // Routing only fills the parent index's UI state, not the
445
+ // autocomplete's isolated one, so without this, the autocomplete
446
+ // would activate with an empty query and fire a useless search.
447
+ // We copy the parent's query into the autocomplete's slot of
448
+ // `_initialUiState` right before flipping `activated`: that's the
449
+ // moment the isolated `<Index>` is about to mount and read it.
450
+ // Doing this later would mean firing a second search to correct
451
+ // the first.
452
+ if (indexUiState.query) {
453
+ var isoIndexId = "ais-autocomplete-".concat(instanceKey);
454
+ var initial = instance._initialUiState;
455
+ initial[isoIndexId] = _object_spread_props._(_object_spread._({}, initial[isoIndexId]), {
456
+ query: indexUiState.query
457
+ });
458
+ }
459
+ setActivated(true);
460
+ };
461
+ return /*#__PURE__*/ _react.default.createElement(Autocomplete, _object_spread_props._(_object_spread._({}, shellRootProps), {
462
+ classNames: classNames
463
+ }), isDetached ? /*#__PURE__*/ _react.default.createElement(AutocompleteDetachedSearchButton, {
464
+ query: (_indexUiState_query = indexUiState.query) !== null && _indexUiState_query !== void 0 ? _indexUiState_query : '',
465
+ placeholder: placeholder,
466
+ classNames: classNames,
467
+ translations: translations,
468
+ onClick: function onClick() {
469
+ setIsModalOpen(true);
470
+ activateWithQueryMirror();
471
+ }
472
+ }) : /*#__PURE__*/ _react.default.createElement(_AutocompleteSearch.AutocompleteSearch, {
473
+ inputProps: {
474
+ id: "autocomplete".concat(domId, "input"),
475
+ role: 'combobox',
476
+ placeholder: placeholder,
477
+ onFocus: activateWithQueryMirror
478
+ },
479
+ clearQuery: function clearQuery() {},
480
+ query: (_indexUiState_query1 = indexUiState.query) !== null && _indexUiState_query1 !== void 0 ? _indexUiState_query1 : '',
481
+ isSearchStalled: false,
482
+ classNames: classNames
483
+ }));
484
+ }
405
485
  var innerAutocomplete = /*#__PURE__*/ _react.default.createElement(InnerAutocomplete, _object_spread_props._(_object_spread._({}, forwardedProps), {
486
+ autoFocus: true,
487
+ domId: domId,
488
+ detached: detached,
406
489
  indicesConfig: indicesConfig,
407
490
  refineSearchBox: refine,
408
491
  isSearchStalled: isSearchStalled,
@@ -411,7 +494,6 @@ function EXPERIMENTAL_Autocomplete(props) {
411
494
  showRecent: showRecent,
412
495
  recentSearchConfig: recentSearchConfig,
413
496
  showQuerySuggestions: normalizedShowQuerySuggestions,
414
- detachedMediaQuery: detachedMediaQuery,
415
497
  translations: translations,
416
498
  showPromptSuggestions: normalizedShowPromptSuggestions,
417
499
  transformItems: effectiveTransformItems,
@@ -430,16 +512,18 @@ function EXPERIMENTAL_Autocomplete(props) {
430
512
  }), innerAutocomplete);
431
513
  }
432
514
  return /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Index, {
433
- EXPERIMENTAL_isolated: true
515
+ EXPERIMENTAL_isolated: true,
516
+ indexId: "ais-autocomplete-".concat(instanceKey)
434
517
  }, /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Configure, searchParameters), indicesConfig.map(function(index) {
435
518
  return /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Index, {
436
519
  key: index.indexName,
437
- indexName: index.indexName
520
+ indexName: index.indexName,
521
+ indexId: "ais-autocomplete-".concat(instanceKey, "-").concat(index.indexName)
438
522
  }, /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Configure, index.searchParameters));
439
523
  }), innerAutocomplete);
440
524
  }
441
525
  function InnerAutocomplete(_0) {
442
- var indicesConfig = _0.indicesConfig, refineSearchBox = _0.refineSearchBox, isSearchStalled = _0.isSearchStalled, getSearchPageURL = _0.getSearchPageURL, userOnSelect = _0.onSelect, indexUiState = _0.indexUiState, isSearchPage = _0.isSearchPage, PanelComponent = _0.panelComponent, showRecent = _0.showRecent, recentSearchConfig = _0.recentSearchConfig, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, chatRenderState = _0.chatRenderState, transformItems = _0.transformItems, placeholder = _0.placeholder, autoFocus = _0.autoFocus, _0_detachedMediaQuery = _0.detachedMediaQuery, detachedMediaQuery = _0_detachedMediaQuery === void 0 ? DEFAULT_DETACHED_MEDIA_QUERY : _0_detachedMediaQuery, translations = _0.translations, classNames = _0.classNames, aiMode = _0.aiMode, props = _object_without_properties._(_0, [
526
+ var indicesConfig = _0.indicesConfig, refineSearchBox = _0.refineSearchBox, isSearchStalled = _0.isSearchStalled, getSearchPageURL = _0.getSearchPageURL, userOnSelect = _0.onSelect, indexUiState = _0.indexUiState, isSearchPage = _0.isSearchPage, PanelComponent = _0.panelComponent, showRecent = _0.showRecent, recentSearchConfig = _0.recentSearchConfig, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, chatRenderState = _0.chatRenderState, transformItems = _0.transformItems, placeholder = _0.placeholder, autoFocus = _0.autoFocus, translations = _0.translations, classNames = _0.classNames, aiMode = _0.aiMode, domId = _0.domId, detached = _0.detached, props = _object_without_properties._(_0, [
443
527
  "indicesConfig",
444
528
  "refineSearchBox",
445
529
  "isSearchStalled",
@@ -456,10 +540,11 @@ function InnerAutocomplete(_0) {
456
540
  "transformItems",
457
541
  "placeholder",
458
542
  "autoFocus",
459
- "detachedMediaQuery",
460
543
  "translations",
461
544
  "classNames",
462
- "aiMode"
545
+ "aiMode",
546
+ "domId",
547
+ "detached"
463
548
  ]);
464
549
  var _indexUiState_query, _ref;
465
550
  var _showPromptSuggestions_searchParameters;
@@ -470,7 +555,7 @@ function InnerAutocomplete(_0) {
470
555
  }
471
556
  }), indices = _useAutocomplete.indices, refineAutocomplete = _useAutocomplete.refine, currentRefinement = _useAutocomplete.currentRefinement;
472
557
  var resolvedQuery = currentRefinement !== undefined ? currentRefinement : (_indexUiState_query = indexUiState.query) !== null && _indexUiState_query !== void 0 ? _indexUiState_query : '';
473
- var _useDetachedMode = useDetachedMode(detachedMediaQuery), isDetached = _useDetachedMode.isDetached, isModalDetached = _useDetachedMode.isModalDetached, isModalOpen = _useDetachedMode.isModalOpen, setIsModalOpen = _useDetachedMode.setIsModalOpen;
558
+ var isDetached = detached.isDetached, isModalDetached = detached.isModalDetached, isModalOpen = detached.isModalOpen, setIsModalOpen = detached.setIsModalOpen;
474
559
  var previousIsDetachedRef = (0, _react.useRef)(isDetached);
475
560
  var _useStorage = useStorage({
476
561
  showRecent: showRecent,
@@ -536,6 +621,7 @@ function InnerAutocomplete(_0) {
536
621
  });
537
622
  var shouldHideEmptyPanel = allIndicesEmpty && recentEmpty && !hasNoResultsTemplate && !PanelComponent;
538
623
  var _usePropGetters = usePropGetters({
624
+ id: domId,
539
625
  indices: indicesForPropGettersWithPromptSuggestions,
540
626
  indicesConfig: indicesConfigForPropGetters,
541
627
  onRefine: function onRefine(query) {
@@ -656,7 +742,7 @@ function InnerAutocomplete(_0) {
656
742
  NoResultsComponent: currentIndexConfig.noResultsComponent,
657
743
  items: hits.map(function(item) {
658
744
  return _object_spread_props._(_object_spread._({}, item), {
659
- __indexName: indexId
745
+ __indexName: indexName
660
746
  });
661
747
  }),
662
748
  getItemProps: getItemProps,
@@ -1,13 +1,13 @@
1
- import { _ as _$1 } from '@swc/helpers/esm/_object_spread.js';
2
- import { _ as _$3 } from '@swc/helpers/esm/_object_spread_props.js';
1
+ import { _ as _$2 } from '@swc/helpers/esm/_object_spread.js';
2
+ import { _ as _$4 } from '@swc/helpers/esm/_object_spread_props.js';
3
3
  import { _ } from '@swc/helpers/esm/_object_without_properties.js';
4
- import { _ as _$5 } from '@swc/helpers/esm/_sliced_to_array.js';
5
- import { _ as _$2 } from '@swc/helpers/esm/_to_consumable_array.js';
6
- import { _ as _$4 } from '@swc/helpers/esm/_type_of.js';
4
+ import { _ as _$1 } from '@swc/helpers/esm/_sliced_to_array.js';
5
+ import { _ as _$3 } from '@swc/helpers/esm/_to_consumable_array.js';
6
+ import { _ as _$5 } from '@swc/helpers/esm/_type_of.js';
7
7
  import { createAutocompleteComponent, createAutocompletePanelComponent, createAutocompleteIndexComponent, createAutocompleteSuggestionComponent, createAutocompletePromptSuggestionComponent, createAutocompleteRecentSearchComponent, createAutocompleteDetachedContainerComponent, createAutocompleteDetachedOverlayComponent, createAutocompleteDetachedFormContainerComponent, createAutocompleteDetachedSearchButtonComponent, createAutocompletePropGetters, createAutocompleteStorage, cx, getPromptSuggestionHits, isPromptSuggestion } from 'instantsearch-ui-components';
8
8
  import { openChat, isChatBusy } from 'instantsearch.js/es/lib/chat/index.js';
9
9
  import 'instantsearch.js/es/lib/utils/index.js';
10
- import React, { createElement, Fragment, useEffect, useMemo, useRef, useState } from 'react';
10
+ import React, { createElement, Fragment, useEffect, useMemo, useRef, useState, useLayoutEffect } from 'react';
11
11
  import { useInstantSearch, useInstantSearchContext, useSearchBox, Index, Configure, Feeds, useAutocomplete } from 'react-instantsearch-core';
12
12
  import { AutocompleteSearch } from '../components/AutocompleteSearch.js';
13
13
  import { Highlight } from './Highlight.js';
@@ -54,11 +54,14 @@ var AutocompleteDetachedSearchButton = createAutocompleteDetachedSearchButtonCom
54
54
  Fragment: Fragment
55
55
  });
56
56
  var id = 0;
57
- var useAutocompleteInstanceId = React.useId ? function() {
58
- return React.useId().replace(/:/g, '');
57
+ // Colons (`:r0:`) preserved so concatenations like `autocomplete:r0:input`
58
+ // have a recognisable boundary; callers that need a colon-free variant for
59
+ // InstantSearch's `indexId` strip them at the use site.
60
+ var useAutocompleteId = React.useId ? function() {
61
+ return React.useId();
59
62
  } : function() {
60
63
  return React.useState(function() {
61
- return "a".concat(id++);
64
+ return ":a".concat(id++, ":");
62
65
  })[0];
63
66
  };
64
67
  var usePropGetters = createAutocompletePropGetters({
@@ -115,12 +118,12 @@ function getMediaQueryList(mediaQuery) {
115
118
  }, [
116
119
  mediaQuery
117
120
  ]);
118
- var _useState = _$5(useState(function() {
121
+ var _useState = _$1(useState(function() {
119
122
  var _getMediaQueryList;
120
123
  return resolvedMediaQuery ? Boolean((_getMediaQueryList = getMediaQueryList(resolvedMediaQuery)) === null || _getMediaQueryList === void 0 ? void 0 : _getMediaQueryList.matches) : false;
121
124
  }), 2), isDetached = _useState[0], setIsDetached = _useState[1];
122
- var _useState1 = _$5(useState(false), 2), isModalOpen = _useState1[0], setIsModalOpen = _useState1[1];
123
- var _useState2 = _$5(useState(false), 2), isModalDetached = _useState2[0], setIsModalDetached = _useState2[1];
125
+ var _useState1 = _$1(useState(false), 2), isModalOpen = _useState1[0], setIsModalOpen = _useState1[1];
126
+ var _useState2 = _$1(useState(false), 2), isModalDetached = _useState2[0], setIsModalDetached = _useState2[1];
124
127
  useEffect(function() {
125
128
  if (!resolvedMediaQuery) {
126
129
  setIsDetached(false);
@@ -210,18 +213,21 @@ function EXPERIMENTAL_Autocomplete(props) {
210
213
  "translations",
211
214
  "transformItems"
212
215
  ]);
213
- var translations = _$1({}, DEFAULT_TRANSLATIONS, userTranslations);
216
+ var autoFocus = restProps.autoFocus, placeholder = restProps.placeholder, classNames = restProps.classNames;
217
+ // Eager-mount only when `autoFocus` is set — otherwise wait for first focus
218
+ // before registering the autocomplete subtree in the search graph.
219
+ var _useState = _$1(useState(autoFocus === true), 2), activated = _useState[0], setActivated = _useState[1];
220
+ var translations = _$2({}, DEFAULT_TRANSLATIONS, userTranslations);
214
221
  var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, indexRenderState = _useInstantSearch.indexRenderState, status = _useInstantSearch.status;
215
222
  var compositionID = useInstantSearchContext().compositionID;
216
- var refine = useSearchBox({}, _$1({
223
+ var refine = useSearchBox({}, _$2({
217
224
  $$type: 'ais.autocomplete',
218
225
  $$widgetType: 'ais.autocomplete'
219
226
  }, props.aiMode ? {
220
227
  opensChat: true
221
228
  } : {})).refine;
222
- // In feeds-mode, indexId disambiguates multiple Autocomplete instances
223
- // sharing the same compositionID. Mirrors the fallback at line 111 for React <18.
224
- var instanceKey = useAutocompleteInstanceId();
229
+ var domId = useAutocompleteId();
230
+ var instanceKey = domId.replace(/:/g, '');
225
231
  if (isFeedsMode && indices !== undefined) {
226
232
  throw new Error('EXPERIMENTAL_Autocomplete: `feeds` and `indices` are mutually exclusive.');
227
233
  }
@@ -229,7 +235,7 @@ function EXPERIMENTAL_Autocomplete(props) {
229
235
  throw new Error('EXPERIMENTAL_Autocomplete in feeds-mode requires a composition-based <InstantSearch> (compositionID must be set).');
230
236
  }
231
237
  var isSearchStalled = status === 'stalled';
232
- var searchParameters = _$1({
238
+ var searchParameters = _$2({
233
239
  hitsPerPage: 5
234
240
  }, userSearchParameters);
235
241
  // In feeds-mode `indexName` carries the feedID so downstream matching
@@ -248,10 +254,10 @@ function EXPERIMENTAL_Autocomplete(props) {
248
254
  getQuery: feed.getQuery,
249
255
  classNames: feed.classNames
250
256
  };
251
- }) : _$2(indices !== null && indices !== void 0 ? indices : []);
257
+ }) : _$3(indices !== null && indices !== void 0 ? indices : []);
252
258
  if (querySuggestionsKey) {
253
259
  var _showQuerySuggestions_classNames, _showQuerySuggestions_classNames1, _showQuerySuggestions_classNames2, _showQuerySuggestions_classNames3;
254
- var querySuggestionsSearchParameters = isFeedsMode ? undefined : _$1({
260
+ var querySuggestionsSearchParameters = isFeedsMode ? undefined : _$2({
255
261
  hitsPerPage: 3
256
262
  }, showQuerySuggestions.searchParameters);
257
263
  config.unshift({
@@ -282,7 +288,7 @@ function EXPERIMENTAL_Autocomplete(props) {
282
288
  }
283
289
  if (promptSuggestionsKey) {
284
290
  var _showPromptSuggestions_classNames, _showPromptSuggestions_classNames1, _showPromptSuggestions_classNames2, _showPromptSuggestions_classNames3;
285
- var promptSuggestionsSearchParameters = isFeedsMode ? undefined : _$1({
291
+ var promptSuggestionsSearchParameters = isFeedsMode ? undefined : _$2({
286
292
  hitsPerPage: 3
287
293
  }, showPromptSuggestions.searchParameters);
288
294
  config.push({
@@ -329,7 +335,7 @@ function EXPERIMENTAL_Autocomplete(props) {
329
335
  return undefined;
330
336
  }
331
337
  if (isFeedsMode) {
332
- return _$3(_$1({}, showQuerySuggestions), {
338
+ return _$4(_$2({}, showQuerySuggestions), {
333
339
  indexName: querySuggestionsKey
334
340
  });
335
341
  }
@@ -344,7 +350,7 @@ function EXPERIMENTAL_Autocomplete(props) {
344
350
  return undefined;
345
351
  }
346
352
  if (isFeedsMode) {
347
- return _$3(_$1({}, showPromptSuggestions), {
353
+ return _$4(_$2({}, showPromptSuggestions), {
348
354
  indexName: promptSuggestionsKey
349
355
  });
350
356
  }
@@ -362,7 +368,7 @@ function EXPERIMENTAL_Autocomplete(props) {
362
368
  var effectiveTransformItems = useMemo(function() {
363
369
  return isFeedsMode ? function(items) {
364
370
  var remapped = items.map(function(item) {
365
- return _$3(_$1({}, item), {
371
+ return _$4(_$2({}, item), {
366
372
  indexName: item.indexId
367
373
  });
368
374
  });
@@ -373,13 +379,13 @@ function EXPERIMENTAL_Autocomplete(props) {
373
379
  transformItems
374
380
  ]);
375
381
  var recentSearchConfig = showRecent ? {
376
- headerComponent: (typeof showRecent === "undefined" ? "undefined" : _$4(showRecent)) === 'object' ? showRecent.headerComponent : undefined,
377
- itemComponent: (typeof showRecent === "undefined" ? "undefined" : _$4(showRecent)) === 'object' && showRecent.itemComponent ? showRecent.itemComponent : AutocompleteRecentSearch,
382
+ headerComponent: (typeof showRecent === "undefined" ? "undefined" : _$5(showRecent)) === 'object' ? showRecent.headerComponent : undefined,
383
+ itemComponent: (typeof showRecent === "undefined" ? "undefined" : _$5(showRecent)) === 'object' && showRecent.itemComponent ? showRecent.itemComponent : AutocompleteRecentSearch,
378
384
  classNames: {
379
- root: cx('ais-AutocompleteRecentSearches', (typeof showRecent === "undefined" ? "undefined" : _$4(showRecent)) === 'object' ? (_showRecent_classNames = showRecent.classNames) === null || _showRecent_classNames === void 0 ? void 0 : _showRecent_classNames.root : undefined),
380
- list: cx('ais-AutocompleteRecentSearchesList', (typeof showRecent === "undefined" ? "undefined" : _$4(showRecent)) === 'object' ? (_showRecent_classNames1 = showRecent.classNames) === null || _showRecent_classNames1 === void 0 ? void 0 : _showRecent_classNames1.list : undefined),
381
- header: cx('ais-AutocompleteRecentSearchesHeader', (typeof showRecent === "undefined" ? "undefined" : _$4(showRecent)) === 'object' ? (_showRecent_classNames2 = showRecent.classNames) === null || _showRecent_classNames2 === void 0 ? void 0 : _showRecent_classNames2.header : undefined),
382
- item: cx('ais-AutocompleteRecentSearchesItem', (typeof showRecent === "undefined" ? "undefined" : _$4(showRecent)) === 'object' ? (_showRecent_classNames3 = showRecent.classNames) === null || _showRecent_classNames3 === void 0 ? void 0 : _showRecent_classNames3.item : undefined)
385
+ root: cx('ais-AutocompleteRecentSearches', (typeof showRecent === "undefined" ? "undefined" : _$5(showRecent)) === 'object' ? (_showRecent_classNames = showRecent.classNames) === null || _showRecent_classNames === void 0 ? void 0 : _showRecent_classNames.root : undefined),
386
+ list: cx('ais-AutocompleteRecentSearchesList', (typeof showRecent === "undefined" ? "undefined" : _$5(showRecent)) === 'object' ? (_showRecent_classNames1 = showRecent.classNames) === null || _showRecent_classNames1 === void 0 ? void 0 : _showRecent_classNames1.list : undefined),
387
+ header: cx('ais-AutocompleteRecentSearchesHeader', (typeof showRecent === "undefined" ? "undefined" : _$5(showRecent)) === 'object' ? (_showRecent_classNames2 = showRecent.classNames) === null || _showRecent_classNames2 === void 0 ? void 0 : _showRecent_classNames2.header : undefined),
388
+ item: cx('ais-AutocompleteRecentSearchesItem', (typeof showRecent === "undefined" ? "undefined" : _$5(showRecent)) === 'object' ? (_showRecent_classNames3 = showRecent.classNames) === null || _showRecent_classNames3 === void 0 ? void 0 : _showRecent_classNames3.item : undefined)
383
389
  }
384
390
  } : undefined;
385
391
  var isSearchPage = useMemo(function() {
@@ -391,7 +397,84 @@ function EXPERIMENTAL_Autocomplete(props) {
391
397
  "indices",
392
398
  "feeds"
393
399
  ]);
394
- var innerAutocomplete = /*#__PURE__*/ React.createElement(InnerAutocomplete, _$3(_$1({}, forwardedProps), {
400
+ var instance = useInstantSearchContext();
401
+ var detached = useDetachedMode(detachedMediaQuery);
402
+ var isDetached = detached.isDetached, setIsModalOpen = detached.setIsModalOpen;
403
+ // Lazy activation only: when `activated` flips from false to true, the
404
+ // newly-mounted isolated `<Index>` schedules the parent's search even
405
+ // though the parent's state hasn't changed. Cancel it so only the
406
+ // autocomplete's own search fires on activation. Skip when `autoFocus`
407
+ // mounts the inner eagerly — the parent's legitimate initial search
408
+ // shares the same defer slot and must not be cancelled.
409
+ var initialActivatedRef = useRef(activated);
410
+ useLayoutEffect(function() {
411
+ if (activated && !initialActivatedRef.current) {
412
+ initialActivatedRef.current = true;
413
+ instance.scheduleSearch.cancel();
414
+ }
415
+ }, [
416
+ activated,
417
+ instance
418
+ ]);
419
+ if (!activated) {
420
+ var _indexUiState_query, _indexUiState_query1;
421
+ restProps.indices; restProps.feeds; restProps.autoFocus; restProps.placeholder; restProps.classNames; restProps.aiMode; restProps.panelComponent; restProps.getSearchPageURL; restProps.onSelect; var shellRootProps = _(restProps, [
422
+ "indices",
423
+ "feeds",
424
+ "autoFocus",
425
+ "placeholder",
426
+ "classNames",
427
+ "aiMode",
428
+ "panelComponent",
429
+ "getSearchPageURL",
430
+ "onSelect"
431
+ ]);
432
+ var activateWithQueryMirror = function activateWithQueryMirror() {
433
+ // Routing only fills the parent index's UI state, not the
434
+ // autocomplete's isolated one, so without this, the autocomplete
435
+ // would activate with an empty query and fire a useless search.
436
+ // We copy the parent's query into the autocomplete's slot of
437
+ // `_initialUiState` right before flipping `activated`: that's the
438
+ // moment the isolated `<Index>` is about to mount and read it.
439
+ // Doing this later would mean firing a second search to correct
440
+ // the first.
441
+ if (indexUiState.query) {
442
+ var isoIndexId = "ais-autocomplete-".concat(instanceKey);
443
+ var initial = instance._initialUiState;
444
+ initial[isoIndexId] = _$4(_$2({}, initial[isoIndexId]), {
445
+ query: indexUiState.query
446
+ });
447
+ }
448
+ setActivated(true);
449
+ };
450
+ return /*#__PURE__*/ React.createElement(Autocomplete, _$4(_$2({}, shellRootProps), {
451
+ classNames: classNames
452
+ }), isDetached ? /*#__PURE__*/ React.createElement(AutocompleteDetachedSearchButton, {
453
+ query: (_indexUiState_query = indexUiState.query) !== null && _indexUiState_query !== void 0 ? _indexUiState_query : '',
454
+ placeholder: placeholder,
455
+ classNames: classNames,
456
+ translations: translations,
457
+ onClick: function onClick() {
458
+ setIsModalOpen(true);
459
+ activateWithQueryMirror();
460
+ }
461
+ }) : /*#__PURE__*/ React.createElement(AutocompleteSearch, {
462
+ inputProps: {
463
+ id: "autocomplete".concat(domId, "input"),
464
+ role: 'combobox',
465
+ placeholder: placeholder,
466
+ onFocus: activateWithQueryMirror
467
+ },
468
+ clearQuery: function clearQuery() {},
469
+ query: (_indexUiState_query1 = indexUiState.query) !== null && _indexUiState_query1 !== void 0 ? _indexUiState_query1 : '',
470
+ isSearchStalled: false,
471
+ classNames: classNames
472
+ }));
473
+ }
474
+ var innerAutocomplete = /*#__PURE__*/ React.createElement(InnerAutocomplete, _$4(_$2({}, forwardedProps), {
475
+ autoFocus: true,
476
+ domId: domId,
477
+ detached: detached,
395
478
  indicesConfig: indicesConfig,
396
479
  refineSearchBox: refine,
397
480
  isSearchStalled: isSearchStalled,
@@ -400,7 +483,6 @@ function EXPERIMENTAL_Autocomplete(props) {
400
483
  showRecent: showRecent,
401
484
  recentSearchConfig: recentSearchConfig,
402
485
  showQuerySuggestions: normalizedShowQuerySuggestions,
403
- detachedMediaQuery: detachedMediaQuery,
404
486
  translations: translations,
405
487
  showPromptSuggestions: normalizedShowPromptSuggestions,
406
488
  transformItems: effectiveTransformItems,
@@ -419,16 +501,18 @@ function EXPERIMENTAL_Autocomplete(props) {
419
501
  }), innerAutocomplete);
420
502
  }
421
503
  return /*#__PURE__*/ React.createElement(Index, {
422
- EXPERIMENTAL_isolated: true
504
+ EXPERIMENTAL_isolated: true,
505
+ indexId: "ais-autocomplete-".concat(instanceKey)
423
506
  }, /*#__PURE__*/ React.createElement(Configure, searchParameters), indicesConfig.map(function(index) {
424
507
  return /*#__PURE__*/ React.createElement(Index, {
425
508
  key: index.indexName,
426
- indexName: index.indexName
509
+ indexName: index.indexName,
510
+ indexId: "ais-autocomplete-".concat(instanceKey, "-").concat(index.indexName)
427
511
  }, /*#__PURE__*/ React.createElement(Configure, index.searchParameters));
428
512
  }), innerAutocomplete);
429
513
  }
430
514
  function InnerAutocomplete(_0) {
431
- var indicesConfig = _0.indicesConfig, refineSearchBox = _0.refineSearchBox, isSearchStalled = _0.isSearchStalled, getSearchPageURL = _0.getSearchPageURL, userOnSelect = _0.onSelect, indexUiState = _0.indexUiState, isSearchPage = _0.isSearchPage, PanelComponent = _0.panelComponent, showRecent = _0.showRecent, recentSearchConfig = _0.recentSearchConfig, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, chatRenderState = _0.chatRenderState, transformItems = _0.transformItems, placeholder = _0.placeholder, autoFocus = _0.autoFocus, _0_detachedMediaQuery = _0.detachedMediaQuery, detachedMediaQuery = _0_detachedMediaQuery === void 0 ? DEFAULT_DETACHED_MEDIA_QUERY : _0_detachedMediaQuery, translations = _0.translations, classNames = _0.classNames, aiMode = _0.aiMode, props = _(_0, [
515
+ var indicesConfig = _0.indicesConfig, refineSearchBox = _0.refineSearchBox, isSearchStalled = _0.isSearchStalled, getSearchPageURL = _0.getSearchPageURL, userOnSelect = _0.onSelect, indexUiState = _0.indexUiState, isSearchPage = _0.isSearchPage, PanelComponent = _0.panelComponent, showRecent = _0.showRecent, recentSearchConfig = _0.recentSearchConfig, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, chatRenderState = _0.chatRenderState, transformItems = _0.transformItems, placeholder = _0.placeholder, autoFocus = _0.autoFocus, translations = _0.translations, classNames = _0.classNames, aiMode = _0.aiMode, domId = _0.domId, detached = _0.detached, props = _(_0, [
432
516
  "indicesConfig",
433
517
  "refineSearchBox",
434
518
  "isSearchStalled",
@@ -445,10 +529,11 @@ function InnerAutocomplete(_0) {
445
529
  "transformItems",
446
530
  "placeholder",
447
531
  "autoFocus",
448
- "detachedMediaQuery",
449
532
  "translations",
450
533
  "classNames",
451
- "aiMode"
534
+ "aiMode",
535
+ "domId",
536
+ "detached"
452
537
  ]);
453
538
  var _indexUiState_query, _ref;
454
539
  var _showPromptSuggestions_searchParameters;
@@ -459,7 +544,7 @@ function InnerAutocomplete(_0) {
459
544
  }
460
545
  }), indices = _useAutocomplete.indices, refineAutocomplete = _useAutocomplete.refine, currentRefinement = _useAutocomplete.currentRefinement;
461
546
  var resolvedQuery = currentRefinement !== undefined ? currentRefinement : (_indexUiState_query = indexUiState.query) !== null && _indexUiState_query !== void 0 ? _indexUiState_query : '';
462
- var _useDetachedMode = useDetachedMode(detachedMediaQuery), isDetached = _useDetachedMode.isDetached, isModalDetached = _useDetachedMode.isModalDetached, isModalOpen = _useDetachedMode.isModalOpen, setIsModalOpen = _useDetachedMode.setIsModalOpen;
547
+ var isDetached = detached.isDetached, isModalDetached = detached.isModalDetached, isModalOpen = detached.isModalOpen, setIsModalOpen = detached.setIsModalOpen;
463
548
  var previousIsDetachedRef = useRef(isDetached);
464
549
  var _useStorage = useStorage({
465
550
  showRecent: showRecent,
@@ -478,11 +563,11 @@ function InnerAutocomplete(_0) {
478
563
  });
479
564
  }) : index.hits;
480
565
  if (index.indexName !== promptSuggestionsIndexName) {
481
- return _$3(_$1({}, index), {
566
+ return _$4(_$2({}, index), {
482
567
  hits: dedupedHits
483
568
  });
484
569
  }
485
- return _$3(_$1({}, index), {
570
+ return _$4(_$2({}, index), {
486
571
  hits: getPromptSuggestionHits({
487
572
  hits: dedupedHits,
488
573
  limit: promptSuggestionsLimit
@@ -502,7 +587,7 @@ function InnerAutocomplete(_0) {
502
587
  if (index.indexName !== promptSuggestionsIndexName) {
503
588
  return index;
504
589
  }
505
- return _$3(_$1({}, index), {
590
+ return _$4(_$2({}, index), {
506
591
  hits: getPromptSuggestionHits({
507
592
  hits: index.hits,
508
593
  limit: promptSuggestionsLimit
@@ -525,6 +610,7 @@ function InnerAutocomplete(_0) {
525
610
  });
526
611
  var shouldHideEmptyPanel = allIndicesEmpty && recentEmpty && !hasNoResultsTemplate && !PanelComponent;
527
612
  var _usePropGetters = usePropGetters({
613
+ id: domId,
528
614
  indices: indicesForPropGettersWithPromptSuggestions,
529
615
  indicesConfig: indicesConfigForPropGetters,
530
616
  onRefine: function onRefine(query) {
@@ -553,7 +639,7 @@ function InnerAutocomplete(_0) {
553
639
  return;
554
640
  }
555
641
  if (!isSearchPage && typeof getSearchPageURL !== 'undefined') {
556
- window.location.href = getSearchPageURL(_$3(_$1({}, indexUiState), {
642
+ window.location.href = getSearchPageURL(_$4(_$2({}, indexUiState), {
557
643
  query: query
558
644
  }));
559
645
  return;
@@ -644,8 +730,8 @@ function InnerAutocomplete(_0) {
644
730
  ItemComponent: currentIndexConfig.itemComponent,
645
731
  NoResultsComponent: currentIndexConfig.noResultsComponent,
646
732
  items: hits.map(function(item) {
647
- return _$3(_$1({}, item), {
648
- __indexName: indexId
733
+ return _$4(_$2({}, item), {
734
+ __indexName: indexName
649
735
  });
650
736
  }),
651
737
  getItemProps: getItemProps,
@@ -691,7 +777,7 @@ function InnerAutocomplete(_0) {
691
777
  aiModeButtonDisabled: aiMode ? isChatBusy(chatRenderState) : undefined,
692
778
  classNames: classNames
693
779
  });
694
- var panelContent = /*#__PURE__*/ React.createElement(AutocompletePanel, _$3(_$1({}, getPanelProps()), {
780
+ var panelContent = /*#__PURE__*/ React.createElement(AutocompletePanel, _$4(_$2({}, getPanelProps()), {
695
781
  classNames: {
696
782
  root: classNames === null || classNames === void 0 ? void 0 : classNames.panel,
697
783
  open: classNames === null || classNames === void 0 ? void 0 : classNames.panelOpen,
@@ -703,14 +789,14 @@ function InnerAutocomplete(_0) {
703
789
  }) : Object.keys(elements).map(function(elementId) {
704
790
  return elements[elementId];
705
791
  }));
706
- var detachedContainerClassNames = isModalDetached ? _$3(_$1({}, classNames), {
792
+ var detachedContainerClassNames = isModalDetached ? _$4(_$2({}, classNames), {
707
793
  detachedContainer: cx('ais-AutocompleteDetachedContainer--modal', classNames === null || classNames === void 0 ? void 0 : classNames.detachedContainer)
708
794
  }) : classNames;
709
795
  var _getRootProps = getRootProps(), rootRef = _getRootProps.ref, rootProps = _(_getRootProps, [
710
796
  "ref"
711
797
  ]);
712
798
  if (isDetached) {
713
- return /*#__PURE__*/ React.createElement(Autocomplete, _$3(_$1({}, props, rootProps), {
799
+ return /*#__PURE__*/ React.createElement(Autocomplete, _$4(_$2({}, props, rootProps), {
714
800
  rootRef: rootRef,
715
801
  classNames: classNames
716
802
  }), /*#__PURE__*/ React.createElement(AutocompleteDetachedSearchButton, {
@@ -736,7 +822,7 @@ function InnerAutocomplete(_0) {
736
822
  }, searchBoxContent), panelContent)));
737
823
  }
738
824
  // Normal (non-detached) rendering
739
- return /*#__PURE__*/ React.createElement(Autocomplete, _$3(_$1({}, props, rootProps), {
825
+ return /*#__PURE__*/ React.createElement(Autocomplete, _$4(_$2({}, props, rootProps), {
740
826
  rootRef: rootRef,
741
827
  classNames: classNames
742
828
  }), searchBoxContent, panelContent);