Turnstile not resolved when form is loaded through Drupal dialog and already loaded js

Created on 12 June 2025, about 2 months ago

Problem/Motivation

Follow-up issue to https://www.drupal.org/project/turnstile/issues/3330710 πŸ› Turnstile's api.js is not getting loaded when form is loaded through Drupal dialog Needs work and to https://www.drupal.org/project/turnstile/issues/3505942 πŸ› (continuation) Turnstile's api.js is not getting loaded when form is loaded through Drupal dialog Active

When loaded through Drupal dialog and with a challenge already in the page, the js command is not thrown.
I think the detection in TurnstileAjaxSubscriber is not correct / covering all use cases.

Turnstile js files are loaded, but the challenge is not rendered.

Steps to reproduce

  • Install Turnstile
  • Add a form on a region (bottom form in my case)
  • Add a link to open a webform on a dialog
  • Turnstile is not loaded/challenged (and throw an error when submitting "The answer you entered for the CAPTCHA was not correct.")

Proposed resolution

Change onResponse Turnstile detection to cover all response with turnstile library.

<?php
  public function onResponse(ResponseEvent $event): void {
    $response = $event->getResponse();
    if ($response instanceof AjaxResponse) {
      $attachments = $response->getAttachments();
      if (!empty($attachments) && isset($attachments['library']) && !empty($attachments['library']) && in_array('turnstile/turnstile.remote', $attachments['library'])) {
        $response->addCommand(new BaseCommand('turnstileRender', []));
      }
    }
  }
?>
πŸ› Bug report
Status

Active

Version

1.1

Component

Code

Created by

πŸ‡«πŸ‡·France nicodh

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024