From 384cc43936cf8392b94337a4e8c98d6516d02506 Mon Sep 17 00:00:00 2001 From: Captain Jack Sparrow <163903675+sussy-code@users.noreply.github.com> Date: Tue, 4 Jun 2024 18:44:24 +0000 Subject: [PATCH] Fix some issues with init of turnstile hopefully --- src/components/overlays/OverlayDisplay.tsx | 3 ++- src/stores/turnstile/index.tsx | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/overlays/OverlayDisplay.tsx b/src/components/overlays/OverlayDisplay.tsx index b1806989..c3dd7bae 100644 --- a/src/components/overlays/OverlayDisplay.tsx +++ b/src/components/overlays/OverlayDisplay.tsx @@ -9,7 +9,7 @@ import { useInternalOverlayRouter, useRouterAnchorUpdate, } from "@/hooks/useOverlayRouter"; -import { TurnstileProvider } from "@/stores/turnstile"; +import { TurnstileProvider, getTurnstile } from "@/stores/turnstile"; export interface OverlayProps { id: string; @@ -20,6 +20,7 @@ export interface OverlayProps { function TurnstileInteractive() { const { t } = useTranslation(); const [show, setShow] = useState(false); + getTurnstile(); // this may not rerender with different dom structure, must be exactly the same always return ( diff --git a/src/stores/turnstile/index.tsx b/src/stores/turnstile/index.tsx index 7a52c26b..ddb47ee1 100644 --- a/src/stores/turnstile/index.tsx +++ b/src/stores/turnstile/index.tsx @@ -81,6 +81,9 @@ export async function getTurnstileToken() { const turnstile = getTurnstile(); try { // I hate turnstile + if (turnstile.controls.isExpired()) { + turnstile.controls.reset(); + } (window as any).turnstile.execute( document.querySelector(`#${turnstile.id}`), {},