fix(signup): fix turnstile key loading#4021
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryLow Risk Overview This makes the Turnstile widget mount only after the env var is read on the client, reducing "missing captcha response" failures during signup. Reviewed by Cursor Bugbot for commit 570436e. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThis PR fixes the Cloudflare Turnstile CAPTCHA widget not mounting on the signup page by deferring the site key lookup to a
Confidence Score: 5/5Safe to merge — the fix correctly defers env var reading to a client-side useEffect, resolving the captcha initialization bug with no regressions. Single-file change with a well-understood fix pattern for next-runtime-env. No logic bugs, no data loss risk, no security issues introduced. The minor hook ordering style deviation (useEffect interleaved among useState declarations) is pre-existing and does not affect behavior. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Browser
participant React
participant nextRuntimeEnv as next-runtime-env
participant Turnstile
Browser->>React: Page load / SSR render
Note over React: turnstileSiteKey = undefined
Note over React: Turnstile NOT rendered (key falsy)
React-->>Browser: HTML (no widget)
Browser->>React: Client hydration (window.__ENV__ set)
React->>React: useEffect fires
React->>nextRuntimeEnv: getEnv('NEXT_PUBLIC_TURNSTILE_SITE_KEY')
nextRuntimeEnv-->>React: 'site-key-value'
React->>React: setTurnstileSiteKey('site-key-value')
React->>React: Re-render
React->>Turnstile: Mount widget with valid siteKey
Turnstile-->>React: Widget ready (execution: execute)
Browser->>React: User submits form
React->>Turnstile: widget.reset()
React->>Turnstile: widget.execute()
Turnstile-->>React: getResponsePromise() resolves with token
React->>Browser: POST /signUp { x-captcha-response: token }
Reviews (1): Last reviewed commit: "fix(signup): fix turnstile key loading" | Re-trigger Greptile |
Summary
Signup form turnstile wasn't mounted as an env var. Using useEffect so we don't hit the
missing captcha responseerrorthe Turnstile component didn't appear in the DOM:
Type of Change
Testing
Checklist
Screenshots/Videos