-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
This issue is automatically created based on existing pull request: #40396: Fix ui-select cache calculation using pixels instead of items
Description (*)
This PR fixes a critical bug in the ui-select component's isSearchKeyCached method that incorrectly uses this.deviation (scroll threshold in pixels) instead of this.pageLimit (items per page) when calculating cached results.
Current Issue:
Line 1239 in vendor/magento/module-ui/view/base/web/js/form/element/ui-select.js:
var totalCached = this.deviation * this.cachedSearchResults[searchKey].lastPage;This mixes units: deviation = 30 pixels (scroll threshold), but the calculation needs item count, not pixels.
Impact:
- With 85 total items and pageLimit=50, it calculates: page 1 = 30 items, page 2 = 60 items, page 3 = 90 items
- This causes 3 AJAX requests instead of the correct 2 requests
- Wastes server resources and creates unnecessary network traffic and duplicates in list
Fix:
Replace this.deviation with this.pageLimit to use the correct unit:
var totalCached = this.pageLimit * this.cachedSearchResults[searchKey].lastPage;Now with 85 items: page 1 = 50 items, page 2 = 100 items → correctly stops at 2 requests (100 ≥ 85).
Manual testing scenarios (*)
- Create a UI component with ui-select that has searchOptions: true configured
- Create a search endpoint that returns 85 total products with pageLimit=50
- Open the dropdown and type a search query
- Scroll to the bottom to trigger pagination
- Open browser DevTools Network tab
- Before fix: Observe 3 AJAX requests (page=1, page=2, page=3)
- Core Magento thinks: page 1 = 30 items, page 2 = 60 items, page 3 = 90 items
- Reality: page 1 = 50 items, page 2 = 100 items
- After fix: Observe only 2 AJAX requests (page=1, page=2)
- Verify all 85 items are loaded correctly
- Test with different totals:
- 100 items: Should load exactly 2 pages (50 + 50)
- 51 items: Should load exactly 2 pages (50 + 1)
- 150 items: Should load exactly 3 pages (50 + 50 + 50)
Questions or comments
This is a simple unit confusion bug where the code mixed pixel measurements (deviation for scroll threshold) with item counts (pageLimit for pagination). The fix ensures the cache calculation uses consistent units (items) throughout.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status