Skip to content

fix: remove redundant checks and add explicit render mode #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 8, 2025

Conversation

nullcoder
Copy link
Owner

Summary

  • Remove redundant type and length checks for environment variables
  • Add explicit render mode to Turnstile script for better control

Changes

  • Simplified env var check: Removed typeof turnstileSiteKey === "string" && turnstileSiteKey.length > 0 as environment variables are either undefined or string values, making these checks redundant
  • Explicit render mode: Added ?render=explicit to the Turnstile script URL to ensure we have full control over when the widget renders

Test plan

  • Turnstile widget still loads correctly
  • No JavaScript errors in console
  • Widget only renders when explicitly called

🤖 Generated with Claude Code

- Remove redundant type and length checks for turnstileSiteKey
  Environment variables are either undefined or string, so simple truthy check is sufficient
- Add ?render=explicit to Turnstile script URL for better control over widget rendering

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

cloudflare-workers-and-pages bot commented Jun 8, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ghostpaste ef89195 Visit preview Jun 08 2025, 05:53 PM

- Replace setInterval polling with Cloudflare's official onload callback mechanism
- Add onloadTurnstileCallback to Window interface
- Update script URL to include onload parameter
- Fix bug where cleanup function wasn't registered when Turnstile was pre-loaded
- Update tests to properly simulate the callback flow
- Better performance and cleaner implementation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@nullcoder nullcoder merged commit 7b967af into main Jun 8, 2025
1 check was pending
@nullcoder nullcoder deleted the fix/turnstile-redundant-checks branch June 8, 2025 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant