diff --git a/src/components/svelte/ContactForm.svelte b/src/components/svelte/ContactForm.svelte index ead2224..f1acd3a 100644 --- a/src/components/svelte/ContactForm.svelte +++ b/src/components/svelte/ContactForm.svelte @@ -15,10 +15,14 @@ let errorMessage = $state('') let turnstileWidgetId: string | null = $state(null) let turnstileContainer: HTMLElement + let turnstileInitialized = false const TURNSTILE_SITEKEY = sitekey - onMount(() => { + function initTurnstile() { + if (turnstileInitialized) return + turnstileInitialized = true + // Wait for Turnstile script to load const interval = setInterval(() => { if (typeof window.turnstile !== 'undefined') { @@ -32,9 +36,10 @@ }) } }, 100) + } + onMount(() => { return () => { - clearInterval(interval) if (turnstileWidgetId !== null && typeof window.turnstile !== 'undefined') { window.turnstile.remove(turnstileWidgetId) } @@ -111,7 +116,7 @@ } -