Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

クローズ
#20,100 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@1070rik がすでに取り組んでいます。

2026年10月26日 から。

  • #20101 @1070rik による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
1/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
javascript, php

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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)

主要言語
PHP
スター
3.6k
フォーク
710
平均マージ
12時間 44分
マージ済み PR(30日)
335

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

craftcms/cms のほかの issue

craftcms/cms の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。