@seekora-ai/ui-sdk-react 0.2.23 → 0.2.24

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.
@@ -301,6 +301,7 @@ class SearchStateManager {
301
301
  constructor(config) {
302
302
  this.listeners = [];
303
303
  this.debounceTimer = null;
304
+ this.notifyScheduled = false;
304
305
  this.client = config.client;
305
306
  this.autoSearch = config.autoSearch !== false;
306
307
  this.debounceMs = config.debounceMs || 300;
@@ -548,19 +549,27 @@ class SearchStateManager {
548
549
  this.state = { ...this.state, ...updates };
549
550
  this.notifyListeners();
550
551
  }
551
- // Notify all listeners of state changes
552
+ // Notify all listeners of state changes, batched via microtask.
553
+ // Multiple synchronous mutations (e.g. addRefinement + page reset)
554
+ // coalesce into a single listener notification.
552
555
  notifyListeners() {
553
- const state = this.getState();
554
- this.listeners.forEach(listener => {
555
- try {
556
- listener(state);
557
- }
558
- catch (err) {
559
- const error = err instanceof Error ? err : new Error(String(err));
560
- log.error('SearchStateManager: Error in listener', {
561
- error: error.message,
562
- });
563
- }
556
+ if (this.notifyScheduled)
557
+ return;
558
+ this.notifyScheduled = true;
559
+ queueMicrotask(() => {
560
+ this.notifyScheduled = false;
561
+ const state = this.getState();
562
+ this.listeners.forEach(listener => {
563
+ try {
564
+ listener(state);
565
+ }
566
+ catch (err) {
567
+ const error = err instanceof Error ? err : new Error(String(err));
568
+ log.error('SearchStateManager: Error in listener', {
569
+ error: error.message,
570
+ });
571
+ }
572
+ });
564
573
  });
565
574
  }
566
575
  /** Explicitly clear results (bypasses keepResultsOnClear) */
@@ -606,10 +615,13 @@ class SearchStateManager {
606
615
  async fetchFilters(options) {
607
616
  log.verbose('SearchStateManager: Fetching filters', { options });
608
617
  try {
609
- const filterString = this.buildFilterString();
618
+ // Do NOT pass refinement-based filters to the Filters API.
619
+ // Facets should be generated from the search query only, not narrowed
620
+ // by active filter selections. This keeps facet options stable when
621
+ // users toggle filters (same behaviour as performSimplifiedFacetSearch
622
+ // in the search API).
610
623
  const response = await this.client.getFilters({
611
624
  q: this.state.query || undefined,
612
- filter: filterString || undefined,
613
625
  ...options,
614
626
  });
615
627
  log.info('SearchStateManager: Filters fetched', {