Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Remove invisible Turnstile widget from layout flow (#2726)

Luke Vella327021715389
diff --git a/apps/web/src/app/[locale]/(auth)/login/components/login-email-form.tsx b/apps/web/src/app/[locale]/(auth)/login/components/login-email-form.tsx
index 5603f66ab..0b218d1a9 100644
--- a/apps/web/src/app/[locale]/(auth)/login/components/login-email-form.tsx
+++ b/apps/web/src/app/[locale]/(auth)/login/components/login-email-form.tsx
@@ -1,7 +1,6 @@
"use client";
import { zodResolver } from "@hookform/resolvers/zod";
import type { TurnstileInstance } from "@marsidev/react-turnstile";
-import { Turnstile } from "@marsidev/react-turnstile";
import { Button } from "@rallly/ui/button";
import {
Form,
@@ -19,6 +18,7 @@ import { useForm } from "react-hook-form";
import * as z from "zod";
import { setVerificationEmail } from "@/app/[locale]/(auth)/login/actions";
+import { Turnstile } from "@/components/turnstile";
import { Trans, useTranslation } from "@/i18n/client";
import { authClient } from "@/lib/auth-client";
import { useFeatureFlag } from "@/lib/feature-flags/client";
@@ -285,13 +285,7 @@ export function LoginWithEmailForm({
<Turnstile
ref={turnstileRef}
siteKey={turnstileSiteKey}
- options={{
- language: i18n.language,
- size: "flexible",
- // Solves invisibly in the background; only shows up when
- // Cloudflare requires an interactive challenge.
- appearance: "interaction-only",
- }}
+ language={i18n.language}
/>
) : null}
<div>
diff --git a/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsx b/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsx
index f6ed43a7c..e03338a82 100644
--- a/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsx
+++ b/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsx
@@ -2,7 +2,6 @@
import { zodResolver } from "@hookform/resolvers/zod";
import type { TurnstileInstance } from "@marsidev/react-turnstile";
-import { Turnstile } from "@marsidev/react-turnstile";
import { Button } from "@rallly/ui/button";
import {
Dialog,
@@ -24,6 +23,7 @@ import React from "react";
import { useForm } from "react-hook-form";
import * as z from "zod";
import { InputOTP } from "@/components/input-otp";
+import { Turnstile } from "@/components/turnstile";
import { Trans, useTranslation } from "@/i18n/client";
import { authClient } from "@/lib/auth-client";
import { useFeatureFlag } from "@/lib/feature-flags/client";
@@ -175,13 +175,7 @@ export function RsvpVerifyEmail({
<Turnstile
ref={turnstileRef}
siteKey={turnstileSiteKey}
- options={{
- language: i18n.language,
- size: "flexible",
- // Solves invisibly in the background; only shows up when
- // Cloudflare requires an interactive challenge.
- appearance: "interaction-only",
- }}
+ language={i18n.language}
onSuccess={(token) => {
void sendOtp(token);
}}
diff --git a/apps/web/src/components/turnstile.tsx b/apps/web/src/components/turnstile.tsx
new file mode 100644
index 000000000..0d154eb03
--- /dev/null
+++ b/apps/web/src/components/turnstile.tsx
@@ -0,0 +1,43 @@
+"use client";
+
+import type { TurnstileInstance } from "@marsidev/react-turnstile";
+import { Turnstile as TurnstileWidget } from "@marsidev/react-turnstile";
+import React from "react";
+
+/**
+ * Cloudflare Turnstile in interaction-only mode. Solves invisibly in the
+ * background; the widget only appears when Cloudflare requires an
+ * interactive challenge. While invisible, the container is removed from
+ * the layout entirely so space-y/gap parents don't add a gap around it —
+ * via inline style, since the library's own inline display would
+ * override a class.
+ */
+export function Turnstile({
+ ref,
+ siteKey,
+ language,
+ onSuccess,
+}: {
+ ref?: React.Ref<TurnstileInstance>;
+ siteKey: string;
+ language: string;
+ onSuccess?: (token: string) => void;
+}) {
+ const [isInteractive, setIsInteractive] = React.useState(false);
+
+ return (
+ <TurnstileWidget
+ ref={ref}
+ siteKey={siteKey}
+ style={isInteractive ? undefined : { display: "none" }}
+ onBeforeInteractive={() => setIsInteractive(true)}
+ onAfterInteractive={() => setIsInteractive(false)}
+ onSuccess={onSuccess}
+ options={{
+ language,
+ size: "flexible",
+ appearance: "interaction-only",
+ }}
+ />
+ );
+}