Repository navigation
Load newsletter Turnstile only after form submission - #117
Conversation
Deploying savjee-be with
|
| Latest commit: |
0870e55
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9349d464.savjee-be.pages.dev |
| Branch Preview URL: | https://fix-newsletter-turnstile-on.savjee-be.pages.dev |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix is ON, but none of the reported issues met your autofix severity threshold.
Reviewed by Cursor Bugbot for commit 0870e55. Configure here.
| // A page restored with Back can retain the disabled button and the spent token. | ||
| window.addEventListener('pageshow', (event) => { | ||
| if (event.persisted) reset(); | ||
| }); |
There was a problem hiding this comment.
Back restore leaves verification running
Low Severity
reset on pageshow clears pending and the spent token but does not cancel the in-flight submit handler. After Back from bfcache during verification, that handler can still receive a token and call HTMLFormElement.prototype.submit, or a later failure can surface on a form that already looks reset. A second Subscribe click is also allowed while the first attempt is still running.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 0870e55. Configure here.


Newsletter forms currently load Turnstile on every page view. This change loads Cloudflare's script only after a visitor submits a valid email address, obtains a verification token, and then posts the form to the existing Worker for server-side verification.
The form shows verification progress, prevents duplicate submissions, and allows retries after script or challenge failures. Returning with Back restores the form and clears the spent token. Multiple forms share one script load and verify independently.
Validation:
Note
Medium Risk
Signup bot protection still depends on Turnstile tokens reaching the existing server verifier; regressions could block legitimate subscribers or weaken abuse resistance if the deferred flow fails in some browsers.
Overview
Newsletter signup no longer pulls Cloudflare Turnstile on every page view. The inline Turnstile script and auto-render widget are removed from
newsletter-box.html; forms that have a site key are wired withdata-newsletter-signupand a placeholder widget container instead.A new bundled client module loads Turnstile only after a valid submit: it shows verifying/submitting status, blocks duplicate attempts, renders an explicit interaction-only challenge, appends
cf-turnstile-response, then posts once via native form submit (same/newsletter/signupWorker path). Failures are retryable;pageshowresets state when the page is restored from bfcache after Back.npm testnow runs alltest/*.test.mjs, including new VM-based tests for lazy load, shared script across multiple forms, failure/retry paths, post-verification validity recheck, and cache restore.Reviewed by Cursor Bugbot for commit 0870e55. Bugbot is set up for automated code reviews on this repo. Configure here.