Skip to main content

Product Search Fixes

Previously, applying product search filters back to back while requests were still in flight caused race conditions. Each filter change triggered a new backend request without canceling the previous one, leading to multiple in-flight requests competing for resources, wasted bandwidth, and potential UI inconsistencies where an older response could overwrite a newer one.


HAPI Elements now cancels in-flight product search requests before issuing a new one. This is done via AbortController with named abort keys, so each search context (filtered products, recommended products, free add-on products) maintains its own cancellation scope. When a new request is initiated, all pending requests within the same scope are aborted first, and CanceledError responses are handled gracefully so that loading states are not cleared incorrectly when a request is superseded.

Product API Functions

The following API functions now support an optional abortKey parameter for request cancellation:

Product Service Functions

The following service functions now cancel any in-flight request within their scope before starting a new one:

  • getProducts -- the underlying service function that wraps searchProducts and passes the abortKey through to the API layer
  • getFilteredProducts -- aborts previous filtered-product requests before fetching
  • getRecommendedProducts -- aborts previous recommended-product requests before fetching
  • getFreeAddOnProducts -- aborts previous free-add-on-product requests before fetching

TypeScript Types

The following types have been updated to reflect the new abortKey parameter:


This optimization is transparent to integrators -- the JavaScript API behaves the same way as before. No changes are needed in existing integrations.