Problem/Motivation
After upgrade Drupal core to 9.4.* I get a JS error when drag fields on "manage display" tab of any content type. When error is present I can't drop field after drag (mouse click and Esc don't work)
error text: Uncaught TypeError: this.$pluginSelect.find(...)[0] is undefined

Admin theme doesn't matter (I tried seven, claro)
Steps to reproduce
- Install Drupal 9.4.x or 9.5.x with the standard installation profile.
- Login as admin
- Navigate to Admin / Structure / Contact Forms
- Choose Manage Form Display from the operations drop-down on the Website Feedback contact form
- Move extra field Send copy to sender to the Disabled section
- Move extra field Send copy to sender back to the into the section with active controls
- Observer the error on the browser console
Original report:
- Go to /admin/structure/types/manage/article/display (if you have content type "article")
- Drag fields many times (sic!)
| Comment | File | Size | Author |
|---|---|---|---|
| Screenshot_20220823_173225.png | 40.41 KB | ivnish | |
| #6 | simplescreenrecorder-2022-08-25_14.33.29.mp4 | 393.23 KB | ivnish |
| #9 | 3305706-uncaught-typeerror-9.patch | 1.15 KB | znerol |
| #23 | 3305706-uncaught-typeerror-23.patch | 539 bytes | znerol |
| #25 | 3305706-uncaught-typeerror-25.patch | 860 bytes | znerol |
Comments
Comment #2
ivnishComment #3
cilefen commentedComment #4
madtSame problem
Comment #5
amin.ankitHi, This issue occurs while upgrading the version from d9 to d9.
Could you please provide steps to reproduce the issue with screenshots?
Thanks,
Comment #6
ivnishComment #7
ivnishComment #8
znerol commentedThis seems to be a problem with extra fields. Steps to reproduce:
I guess that #3239134: Refactor (if feasible) uses of the jQuery val function to use VanillaJS introduced this problem.
this.$pluginSelect.find('option')[0]doesn't seem return anything for extra fields. The most elegant solution would be to use optional chaining operator here.Comment #9
znerol commentedThis is still a problem in 9.5.x. Posting a patch for that branch, needs to be backported afterwards I guess.
Comment #10
smustgrave commentedPatch is failing to apply and it will need a test if it's a bug.
Comment #11
znerol commentedIndeed. The patch is just an attempt to point to the problematic line. It would be awesome if somebody who knows the frontend workflow could pickup here.
Also I'm unsure whether it is okay to use operator chaining, since this seems to be a recent addition to JavaScript IIRC. Would be cool if we get feedback from frontend folks in this regard.
Comment #12
smustgrave commentedSo I tried to replicate actually.
On D9.5
Claro admin theme.
Went to admin/structure/types/manage/article/display
Dragged fields around 20+ times
Dragged fields around 10+ times, saved, dragged around another 20+ times.
Can't replicate the issue.
Moving to PNMI since it's a new issue but tagging for needs steps to reproduce.
Comment #13
znerol commentedThis affects extra fields (not normal fields), please try the repro in #8 (contacts has lots of extra fields). The issue is reproducible 100% in D9.4 and D9.5. I strongly suspect that #3239134: Refactor (if feasible) uses of the jQuery val function to use VanillaJS caused the regression from D9.3.
Comment #14
znerol commentedComment #15
znerol commentedComment #16
znerol commentedIf you like to repro this using content types instead of contact forms, then do the following:
Comment #17
smustgrave commentedYup following the new steps I was able to replicate.
Comment #18
smustgrave commentedMoving to 10.1 because not sure how else to test for console errors.
And https://www.drupal.org/project/drupal/issues/3293090 made it into 10.x
Comment #19
sandeepsingh199 commentedjavascript console error fixed. please check and review.
Comment #20
sandeepsingh199 commentedComment #21
smustgrave commented@SandeepSingh199 thank you for the patch but it failed to apply. And is missing the tests. For contributions please read the existing tags and comments for what is needed and test the patch locally. Removing credit as #19 should be ignored.
Comment #22
mlncn commentedThis makes a core feature of Drupal nearly unusable for a sitebuilder who doesn't know how to turn off JavaScript (selecting "show weights" is only a workaround if done before and instead of trying to drag; the dragging stays stuck). Upping to major.
Comment #23
znerol commentedReroll of #9 for Drupal 10.1. JavaScript ES6 build step was removed in #3278415: Remove usages of the JavaScript ES6 build step, the build step itself, and associated dev dependencies, hence we can work on the source file directly. Also support for Internet Explorer was dropped a while ago, thus optional chaining can be used in core JS now.
Still needs tests. Switching to needs review nevertheless in order to trigger a test-run.
Comment #24
znerol commentedI guess, tests should go here
core/modules/field_ui/tests/src/FunctionalJavascript/EntityDisplayTest.php, I'm going to try cooking up something.Comment #25
znerol commentedOk, so it seems we cannot use optional changing right now because
scripts/dev/commit-code-check.shis not ready for that yet.Thus, reroll of #19 with line wrapping adapted in a way to make the patch a bit easier to read. Still needs tests.
Comment #26
znerol commentedComment #27
znerol commentedSimple test case added to the existing
testExtraFields()method.Comment #29
znerol commentedUhm, the test-only patch passes even though it should fail. Setting to needs work, I hope that somebody who has a better understanding of the frontend test suite will pick this up.
Comment #30
znerol commentedStepping through the tests with php debugger and chromium inspector side-by-side revealed that minks
dragTo()method doesn't really work exactly like a manual drag-drop action. E.g., a manual drag-drop will invokeDrupal.fieldUIOverview.onSwap()repeatedly until the mouse button is released. MinksdragTo()results in no invocation ofonSwap()at all.In order to trigger the error it is necessary to run the test case in a separate test method and drag-drop
#display-extra-field-hidden(extra field which is initially in hidden area) on top of#display-extra-field(extra field which is initially in content area).Comment #32
znerol commentedRegrettably #30 did not fail the expected test.
Comment #33
znerol commentedFiled #3331835: Some JavaScript errors are not recorded during test runs.
Comment #34
znerol commentedSo, with the patch in #3331835: Some JavaScript errors are not recorded during test runs and the test-only patch from #30 I actually get the following (expected) test fail:
Comment #35
znerol commentedThis is patch from #25 with appropriate test methods in
core/**/FunctionalJavascript/EntityDisplayTest.phpandcore/**/FunctionalJavascriptTests/Theme/ClaroEntityDisplayTest.php.3305706-uncaught-typeerror-35-TEST_ONLY_plus_3331835.patchalso includes the necessary bits of #3331835-8: Some JavaScript errors are not recorded during test runs.Comment #37
znerol commentedFrom my point of view this is ready now. I guess we need to come to a decision on whether this issue should be blocked on #3331835: Some JavaScript errors are not recorded during test runs or whether it can be committed despite the fact that the test-only patch currently is not resulting in the expected test fail.
Comment #38
znerol commentedComment #39
larowlan@smustgrave pinged me to flag the issue here w.r.t the testing. I discussed it with @xjm to review the three possible approaches:
* Commit with the test that doesn't fail and fix the testing bug separately
* Block this on the testing bug
* Commit the fix here and move the tests to a followup postponed on the testing bug
@xjm felt that because this is major, the third option seems like the best approach. She also bumped the testing bug to critical.
So can we get a followup for the tests that is postponed on this and the testing bug, and a patch here with just the fixes.
Because this is a bug it can be committed right back to 9.5, so we'll need a 9.5 patch with the compiled JS (non ES6) too I think.
Comment #40
larowlanAdding more keywords to the issue title, found a couple of duplicates and related them back to this one
Comment #41
smustgrave commentedThanks @larowlan!
So @znerol can you upload the fix only from #35. Would do it myself but then I can't be reviewer.
Tagging for followup to create that postponed ticket for the tests.
Comment #42
znerol commentedPatches for 10.1.x and 9.5.x without tests.
Comment #43
znerol commentedFollow-up #3332148: [PP-1] Test cases for extra field drag&drop issue
Comment #44
spokje- Code changes make sense.
- TestBot agrees in #35 where we still have the tests.
- #42 contains only the fix itself, not the tests, as requested in #39.
- The d9 patch in #42 contains the fix only, whilst doing the es6-JS-jig.
All in all nice work and sleuthing @znerol!
RTBC for me.
Comment #49
larowlanAdding credit from #3295724: Unable to move fields to an empty area in the display mode. which I closed as a duplicate
Comment #50
larowlanI think we can just write this as
this.$pluginSelect.find('option')[0]?.valuefor the D10 version where we don't have to support IE11 in D10+https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operat...
We still need this dance for the D9 version though.
Comment #51
spokje@larowlan: I think you're spot on (per usual) and this approach was tried in #23.
Sadly, as @znerol already discribed in #25,
scripts/dev/commit-code-check.shisn't ready for optional chaining in JavaScript (yet?). See https://www.drupal.org/pift-ci-job/2561443 for the "TestBot-Says-No!" result.I'll open a follow-up so that can be addressed, but I think, since this is a Major, we should get this in ASAP and not postpone this on our tooling not being up to scratch. So back to RTBC. Happy to be educated on why this was a potential bad status change.
INSTA-EDIT: Opened #3335653: commit-code-check.sh doesn't allow optional chaining in JavaScript for the
commit-code-check.shwoes.Comment #52
larowlanYep I agree with that approach - will pick this up tomorrow
Comment #53
spokjeProbably too late in larowlan-land by now *shakes fist in anger at time zones*, but it would be nice if we can get this Major one in.
Comment #54
larowlanAdding issue credits, crediting @SandeepSingh199 as I disagree with @smustgrave and feel they were trying to help the issue move forward
Crediting @smustgrave and @Spokje for keeping the issue moving, issue summary updates, filing follow ups etc
Comment #58
larowlanCommitted to 10.1.x and backported to 10.0.x
Committed to 9.5.x
Sorry for taking a bit longer, yesterday was busy.
Comment #59
spokjeThanks @larowlan
No worries, that's why I desperately try to avoid terms like "tomorrow" without adding "-ish" to cover my behind... ;)
Comment #63
smustgrave commentedClosed #3295701: Uncaught TypeError: Cannot read properties of undefined (reading 'value') as duplicate