[5.x]: Closing an element selector modal while it loads makes it load every element in the background
I maintainer di solito rispondono entro 1 giorno
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
- Ambito
- backend, frontend, performance
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
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):
- Create a volume with a few hundred images (I used 350) and an Assets field for it on an entry type.
- Edit an entry and click Add an asset.
- 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/bodyor the firstactions/element-indexes/get-elementsrequest is in flight). - Watch the network panel and the
queuetable.
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()checkscontainerScrollHeight - containerScrollTop <= containerHeight + 15. Once the modal is hidden (display: none) all three values are0, so the check is always true. Verified in the console after closing:scrollHeight0,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
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di craftcms/cms
-
repo:cms
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
craftcms/cms#20235 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug repo:cms
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
craftcms/cms#20205 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[6.x]: Element index View menu: sort direction buttons only update after the table has loadedApertabug repo:cms
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
craftcms/cms#20203 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[5.x]: Moving an asset with “Replace it” throws TypeError: volumeUid must be of type string, null givenForse già presa @i-just l’ha presa 2 giorni fa. Apertabug repo:cms
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
craftcms/cms#20128 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
repo:cms
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
craftcms/cms#20234 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di craftcms/cms
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
0. Needs triage bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
nextcloud/fulltextsearch#1061 ·
I maintainer di solito rispondono entro 1 giorno
-
PHP 8.6 compatibilityAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
-
[Resource]: Claude KitApertaresource-submission validation-passed
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
hesreallyhim/awesome-claude-code#3375 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno