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:
searchProducts-- the core product search endpoint (GET /products/search/)getProducts-- fetches products by ID
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 wrapssearchProductsand passes theabortKeythrough to the API layergetFilteredProducts-- aborts previous filtered-product requests before fetchinggetRecommendedProducts-- aborts previous recommended-product requests before fetchinggetFreeAddOnProducts-- aborts previous free-add-on-product requests before fetching
TypeScript Types
The following types have been updated to reflect the new abortKey parameter:
ProductServiceGetProductsHandlerinservice.types.ts-- addedabortKey?: stringparameterWindowHapiAPIProductRequestsinapi.types.ts--searchProductsandgetProductsnow includeabortKey?: string
This optimization is transparent to integrators -- the JavaScript API behaves the same way as before. No changes are needed in existing integrations.