Skip to content

Conversation

@tanthammar
Copy link
Contributor

Problem:
When the Turnstile field becomes hidden and then visible again (e.g., switching tabs, collapsing panels, or dynamic content changes), the Cloudflare Turnstile widget is destroyed and doesn't re-initialize, leaving users unable to complete the captcha.

Solution:
Added an IntersectionObserver to detect when the Turnstile container enters the viewport and automatically re-renders the widget if it's missing. Includes a safety check to ensure the Turnstile API is loaded before attempting to render.

Changes:

  • Added IntersectionObserver in the Alpine.js x-init to monitor element visibility
  • Added window.turnstile check to prevent rendering before API loads
  • Added element existence check before observing

Probably fixes #27

  Problem:
  When the Turnstile field becomes hidden and then visible again (e.g., switching tabs, collapsing panels, or dynamic content changes),
  the Cloudflare Turnstile widget is destroyed and doesn't re-initialize, leaving users unable to complete the captcha.

  Solution:
  Added an IntersectionObserver to detect when the Turnstile container enters the viewport and automatically re-renders the widget if
  it's missing. Includes a safety check to ensure the Turnstile API is loaded before attempting to render.

  Changes:
  - Added IntersectionObserver in the Alpine.js x-init to monitor element visibility
  - Added window.turnstile check to prevent rendering before API loads
  - Added element existence check before observing

  Testing:
  - Place Turnstile field in collapsible content or tabs
  - Hide and show the container multiple times
  - Verify captcha re-appears and functions correctly
Fix destroyed when element visibility changes
@ousid ousid merged commit f22017e into coderflexx:2.x Sep 17, 2025
9 checks passed
@ousid
Copy link
Member

ousid commented Sep 17, 2025

@tanthammar Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Captcha not being initialised when using wire:navigate

2 participants