Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[5.x]: Closing an element selector modal while it loads makes it load every element in the background

Chiusa
#20,100 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@1070rik ci sta già lavorando.

Dal 26/10/2026.

  • #20101 di @1070rik — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
1/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
javascript, php

Direzione di ricerca

Start in src/web/assets/cp/src/js/BaseElementIndexView.js and trace canLoadMore() and the maybeLoadMore() callbacks after requests complete. Reproduce by closing an element selector modal while its first batch is loading, then check the network panel for continued get-more-elements requests. Done means loading stops while the scroller is hidden and resumes when it becomes visible; an open linked pull request indicates work is already underway.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

repo:cms
What happened?

If an element selector modal is closed while its first batch of elements is still loading, the (now hidden) element index view keeps requesting element-indexes/get-more-elements, batch after batch, until the entire source has been loaded.

For an Assets field this renders thumbnails for every asset in the volume, and since thumbnails aren't generated before page load by default, every thumbnail pushes a GenerateImageTransform queue job. On a production site with an ~11k-image volume, a single editor closing the asset modal at the wrong moment caused 114 get-more-elements requests in ~90 seconds and ~22k queued jobs.

Steps to reproduce (fresh Craft 5.11.5.1 install, no plugins, default config):

  1. Create a volume with a few hundred images (I used 350) and an Assets field for it on an entry type.
  2. Edit an entry and click Add an asset.
  3. Press Esc as soon as the modal has faded in, before the first batch of assets has rendered (i.e. while actions/element-selector-modals/body or the first actions/element-indexes/get-elements request is in flight).
  4. Watch the network panel and the queue table.

Expected: no more requests after the modal is closed; the queue contains jobs for the first batch only (200 for 100 assets).

Actual: get-more-elements fires until the whole source is loaded (3 requests for 350 assets), and the queue contains 700 GenerateImageTransform jobs.

Scenario (fresh install, 350 assets) get-more-elements Assets loaded Queued jobs
Modal open 30 s, no scrolling 0 100 200
Esc right after element-selector-modals/body is sent 3 350 700
Esc while the first get-elements is in flight 3 350 700
Esc after the first batch has rendered 0 100 200

Cause

In src/web/assets/cp/src/js/BaseElementIndexView.js:

  • Element selector modals aren't paginated, so the view calls maybeLoadMore() right after it's created and again after every completed batch (// Is there room to load more right now?).
  • For a non-window scroller, canLoadMore() checks containerScrollHeight - containerScrollTop <= containerHeight + 15. Once the modal is hidden (display: none) all three values are 0, so the check is always true. Verified in the console after closing: scrollHeight 0, scrollTop() 0, outerHeight() 0, canLoadMore() → true.
  • Closing the modal doesn't destroy the element index, and the callback of an in-flight request still calls maybeLoadMore().

Returning false from canLoadMore() when a non-window scroller isn't visible fixes it; loading resumes normally (on scroll) when the modal is reopened:

if (this.$scroller[0] !== Garnish.$win[0] && !this.$scroller.is(':visible')) {
  return false;
}
Craft CMS version

5.11.5.1 (also seen on 5.11.1)

PHP version

8.3

Operating system and version

macOS (local repro), Linux (production)

Database type and version

MySQL

Image driver and version

Imagick 3.8.1 (ImageMagick 7.1.2) locally; GD in production

Installed plugins and versions

None (fresh install)

Lingua principale
PHP
Stelle
3.6k
Fork
710
Merge medio
12h 44m
PR unite (30g)
335

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di craftcms/cms

Tutte le issue di craftcms/cms

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.