Fix Race Conditions in AJAX Processing

Created on 22 May 2025, about 1 month ago

Problem/Motivation

In hook acquia_optimize_form_node_form_alter there a Race condition which we need to avoid https://git.drupalcode.org/project/acquia_optimize/-/blob/1.x/acquia_opt...

Proposed resolution

Use form state storage for tracking state instead of user input, something like this:

$stage = $form_state->get('acquia_optimize_stage') ?: 'initial';
  $form_state_input = $form_state->getUserInput();
  $is_ajax = array_key_exists('_drupal_ajax', $form_state_input) && $form_state_input['_drupal_ajax'] === '1';
  
  if ($is_ajax && $form_state->getTriggeringElement()['#name'] === 'acquia_optimize_scan_button') {
    $form_state->set('acquia_optimize_stage', 'scanning');
    $stage = 'scanning';
  }

Or please feel free to implement a better approach.

📌 Task
Status

Active

Version

1.1

Component

Code

Created by

🇮🇳India ankitv18

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024