Skip to content

Fix Turnstile script firing callback before DOM loaded#7

Open
connordufault wants to merge 1 commit into
FireMultimedia:mainfrom
fjorgedigital:fix/turnstile-script-dom-load-order
Open

Fix Turnstile script firing callback before DOM loaded#7
connordufault wants to merge 1 commit into
FireMultimedia:mainfrom
fjorgedigital:fix/turnstile-script-dom-load-order

Conversation

@connordufault
Copy link
Copy Markdown

@connordufault connordufault commented May 6, 2026

When "Explicit Consent" is disabled in the field settings for the Turnstile field, the Turnstile script loads and fires the callback function before the DOM has fully loaded. Since the DOM hasn't fully loaded yet, the document.getElementById("cf_turnstile") in onloadTurnstileCallback() returns null and Turnstile fails to render with the error Uncaught TurnstileError: [Cloudflare Turnstile] Invalid type for parameter "container", expected "string" or an implementation of "HTMLElement".

This PR sets the defer attribute on the Turnstile script tag so that it does not execute until the DOM is fully loaded.

Fixes #6

@Richardvd
Copy link
Copy Markdown

Thank you for your contribution. My colleague will review this commit.

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.

Turnstile doesn't show when page is first loaded but shows up if page is refreshed

2 participants