Skip to content

[Issue] Fix ui-select cache calculation using pixels instead of items #40397

@m2-assistant

Description

@m2-assistant

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 (*)

  1. Create a UI component with ui-select that has searchOptions: true configured
  2. Create a search endpoint that returns 85 total products with pageLimit=50
  3. Open the dropdown and type a search query
  4. Scroll to the bottom to trigger pagination
  5. Open browser DevTools Network tab
  6. 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
  7. After fix: Observe only 2 AJAX requests (page=1, page=2)
  8. Verify all 85 items are loaded correctly
  9. 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

No one assigned

    Labels

    Issue: ready for confirmationReported on 2.4.xIndicates original Magento version for the Issue report.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    Status

    Ready for Confirmation

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions