Problem/Motivation
When there is a single media item thumbnail, attempting to drag that thumbnail causes a JavaScript error:
media_library.widget.js?v=9.5.0:17 Uncaught TypeError: Cannot set properties of undefined (setting 'value')
at HTMLDivElement.<anonymous> (media_library.widget.js?v=9.5.0:17:71)
at Function.each (jquery.min.js?v=3.6.2:2:3003)
at E.fn.init.each (jquery.min.js?v=3.6.2:2:1481)
at Bt.onEnd (media_library.widget.js?v=9.5.0:16:34)
at W (Sortable.min.js?v=1.15.0:2:11012)
at U (Sortable.min.js?v=1.15.0:2:11592)
at Bt._onDrop (Sortable.min.js?v=1.15.0:2:28869)
(anonymous) @ media_library.widget.js?v=9.5.0:17
each @ jquery.min.js?v=3.6.2:2
each @ jquery.min.js?v=3.6.2:2
onEnd @ media_library.widget.js?v=9.5.0:16
W @ Sortable.min.js?v=1.15.0:2
U @ Sortable.min.js?v=1.15.0:2
_onDrop @ Sortable.min.js?v=1.15.0:2
On some Android phones in some versions of Chrome and Firefox, this freezes the browser. You can no longer scroll up and down on the page. You can interact with text fields that are currently visible, but that's it. You need to tap the URL in the location bar and reload the page.
My browser is Chrome 108 on Android 13 on a Pixel 6:
https://whatismybrowser.com/w/PJHS89R
This does not happen on an iPhone in Chrome (or in Safari).
Steps to reproduce
- Create a content type with a Media image field, setting the Form Display of that field to use the "Media Library" widget.
- Create a node of that content type with 1 image media item.
- Go to the edit form.
- Click on the thumbnail (see screenshot) of the image media item and drag it.
- See JavaScript error in console log. On some Android phones, see that the browser basically freezes.

I confirmed this on a core-only install of Drupal 9.4.9 on simplytest.me. You can see it here until it goes away:
Username / password: admin / admin
https://master-ud8vbaylkh6cdxhro6uqbh33z7z4suuk.tugboatqa.com/node/1/edit
I created a short video of the issue here where (1) I scroll up and down successfully, (2) click the thumbnail, (3) try to scroll, but can't, (4) click a text field to give it focus and still fail to scroll, (5) click outside the text field to remove focus and still fail to scroll:
https://photos.google.com/share/AF1QipMPBJXWaWRDfb0VPBdCPZhP2p4JijZg8odp...
Proposed resolution
Dragging a thumbnail image should cause JavaScript errors or freeze the browser.
Remaining tasks
Diagnose issue.- Patch code.
- Commit to core.
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | interdiff-17_20.txt | 747 bytes | gauravvvv |
| #20 | 3327234-20.patch | 765 bytes | gauravvvv |
| #18 | 3327234-nr-bot.txt | 1.4 KB | needs-review-queue-bot |
| #17 | 3327234-17.patch | 742 bytes | volkerk |
| #13 | 3327234-13.drag-single-media-item.patch | 1.41 KB | jrb |
Comments
Comment #2
seanpb commentedI also see this same issue on mobile chrome on android, right after tapping on the thumbnail image. On mobile firefox, the same thing happens, not on tap, but on tap, hold, and drag.
FF: https://whatismybrowser.com/w/B34ZRTY
Chrome: https://whatismybrowser.com/w/67GAR74
Comment #3
jrbComment #4
cilefen commentedCould someone get the browser console logs please?
In which specific version of Drupal did this break?
Comment #5
jrbThe simplytest.me site is Drupal 9.4.9. It does the same on 9.4.8.
Comment #6
ameer khan commentedI test with an older version of android & chrome. Unable to reproduce the issue. I can tab the media, hold & download, and also able to remove the media.
https://www.whatismybrowser.com/w/FPX8YJK
Then I updated the chrome to latest version (108) but still not able to reproduce. Not freezing.
https://www.whatismybrowser.com/w/999HGD8
Drupal version: 9.4.9
Comment #7
jrbI added screenshot and a short video showing the bug to the description.
New simplytest.me (Drupal 9.5.0) here:
Username / password: admin / admin
https://master-ud8vbaylkh6cdxhro6uqbh33z7z4suuk.tugboatqa.com/node/1/edit
Several people including a client have seen this. One other person with an older phone did not see this problem. Their phone:
Chrome 93 on Android (Pie) - Motorola Moto G Moto G moto g(6)
https://whatismybrowser.com/w/DG7GYH8
Comment #8
jrbJust did the debugging via USB on my phone and got this JavaScript error in the logs:
The error is at the
$(child).find()line of this code in media_library.widget.js:Comment #9
jrbHere's the markup for div.js-media-library-selection. It looks like the problem is that the find(.'js-media-library-item-weight') returns nothing, probably because there's only 1 media item.
Comment #10
jrbYeah, if I change the cardinality of the media image field to 2 and select 2 items, there are no problems with clicking on the image thumbnails. The div.js-media-library-selection now includes two input.js-media-library-item-weight elements.
I'm not sure which is the proper solution?
Drupal.behaviors.MediaLibraryWidgetSortableJS to not run or break when there's only 1 item.Drupal.behaviors.MediaLibraryWidgetDisableButton.Comment #11
jrbSo, now that I know what it is, I am able to recreate the issue on desktop by dragging the thumbnail rather than just clicking it. It doesn't lock up the screen the way it does on some phones, but it does throw the JavaScript error.
Comment #12
jrbUpdated issue title and description now that the problem is better understood.
Comment #13
jrbAttached is a patch that fixes this issue by not setting up Sortable drag-and-drop if there's only 1 item.
Comment #14
jrbThis issue was caused by the changes in #3102402: Remove weight field from Media Library widget when only single media can be attached.
Comment #16
cilefen commentedComment #17
volkerk commentedDrupal 10 version of the patch.
Comment #18
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #19
Yogesh Sahu commentedComment #20
gauravvvv commentedFixed custom commands failed, Attached interdiff for same
Comment #21
Yogesh Sahu commentedComment #22
smustgrave commentedCan confirm the issue in D10.1
Next steps would be to write a test case showing the issue.
Comment #24
jrb