Simultaneous AJAX submissions result in form cache not getting updated for the second submission

Created on 21 April 2017, over 7 years ago
Updated 30 January 2023, almost 2 years ago

Simultaneous AJAX submissions result in form cache not getting updated for the second submission.

First AJAX request enters with form_id: form-F33rMm15SpMLv373G_xn3hRopsteTfkhm70Wi1PceSw
New form is built with new form_id: form-JR1EXYiJjXD6F4YgT2Dkq_sd2oJcSQfr1g-9Ai8MDK4
Response contains

{
  "command": "update_build_id",
  "old": "form-F33rMm15SpMLv373G_xn3hRopsteTfkhm70Wi1PceSw",
  "new": "form-JR1EXYiJjXD6F4YgT2Dkq_sd2oJcSQfr1g-9Ai8MDK4"
} 

which updates form_build_id using update_build_id in ajax.js

update_build_id: function (ajax, response, status) {
  $('input[name="form_build_id"][value="' + response.old + '"]').val(response.new);
}

Second AJAX request enters with same original form_build_id as first form-F33rMm15SpMLv373G_xn3hRopsteTfkhm70Wi1PceSw
New form is built with form_id: form-CyMki8IJH0TDuqWVj3Hn0DMqrYvIoNyviLbKcJfosoc
Response contains

{
  "command": "update_build_id",
  "old": "form-F33rMm15SpMLv373G_xn3hRopsteTfkhm70Wi1PceSw",
  "new": "form-CyMki8IJH0TDuqWVj3Hn0DMqrYvIoNyviLbKcJfosoc"
} 

however as form_build_id was updated by first request, the input field is not found in update_build_id.

Proposed change is to update form_build_id without using value if only one form exists on the page.

update_build_id: function (ajax, response, status) {
  var build_ids = $('input[name="form_build_id"]');
  if (build_ids.length == 1) {
   $('input[name="form_build_id"]').val(response.new);
  } else {
    $('input[name="form_build_id"][value="' + response.old + '"]').val(response.new);
  }
},

or update the form_build_id without using value if one cannot be found with the value of response.old

update_build_id: function (ajax, response, status) {
  var old_build_id = $('input[name="form_build_id"][value="' + response.old + '"]');
  if (old_build_id.length == 0) {
    $('input[name="form_build_id"]').val(response.new);
  } else {
    $('input[name="form_build_id"][value="' + response.old + '"]').val(response.new);
  }
}

Repro steps:

  1. click two ajax buttons at the same time (the second button must be clicked before the first one finishes processing). refer to image 1
  2. search through the response of each ajax submission for "update_build_id" and copy that whole command somewhere for reference. refer to image 2
  3. compare two responses. they will have the same "old" build id. refer to image 3

alternatively, you can put a breakpoint at the update_build_id function in core/misc/ajax.js and inspect the response data.

πŸ› Bug report
Status

Needs work

Version

9.5

Component
AjaxΒ  β†’

Last updated about 3 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States Tyler_Rivard

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or 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.

Production build 0.71.5 2024