-
Notifications
You must be signed in to change notification settings - Fork 16
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
The Cloudflare verification widget is not rendered when visiting the turbo links enabled page #63
Comments
This could be solved with the following:
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
if (document.querySelector(".cf-turnstile") && window.turnstile) {
window.turnstile.render(".cf-turnstile");
}
}
}
<div data-controller="cloudflare-turnstile">
<%= cloudflare_turnstile %>
</div> It works fine, what do you think? |
Thanks @AliOsm, for the suggestion and please accept my apologies for the delayed response. It works fine, and I feel it is a cleaner and better solution. Thank you for sharing it.👍 |
It works fine, i feel like this should be in the readme. |
The proper fix is to tell turbo to simply reload the script <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer data-turbo-track="reload" data-turbo-temporary="true"></script> Could you please let us add custom configuration for that and include documentation? Hotwire + Turbo is used a lot by Rails community it even ships by default with Rails 7 now. Temporary patch that works. Add this in the initializer: module RailsCloudflareTurnstileTurboPatch
def cloudflare_turnstile_script_tag(async: true, defer: true)
super.sub("></script>", " data-turbo-track=\"reload\" data-turbo-temporary=\"true\"></script>").html_safe
end
end
RailsCloudflareTurnstile::ViewHelpers.prepend(RailsCloudflareTurnstileTurboPatch) @yash-learner it seems you said you tried but it does work fine. Turbolinks has been long dead, you should consider upgrading to Turbo. I use Turbo v8 Edit The trick was |
I'm currently using your rails_cloudflare_turnstile gem in a Rails project and have encountered an issue. The gem seems to not work properly with pages using Turbolinks.
The Cloudflare widget is not rendered on a page which has turbolinks enabled, but the Cloudflare widget gets rendered on the same page on a full-page reload (refresh).
The things I tried
data-turbolinks="false"
anddata: { turbolinks: false }
. This is working, as disabling the turbolinks on the link will make a full-page reload.rails-cloudflare-turnstile/lib/rails_cloudflare_turnstile/view_helpers.rb
Line 19 in e0ea972
'data-turbolinks-track': 'reload'
. This attribute tells to do a full page reload when visiting the turbo links, but this change does not work and the widget is not rendered when visits pages with turbolinks enabled.turbolinks:load
event havingdata-turbolinks-track="reload"
- This works and renders the widget when visiting the turbolinks enabled pages. I have done this in two ways.application.js
This can a problem because in the future if the version of Cloudflare is changed to
v0
tov1
..I had overided the method in
cloudflare_turnstile.rb
initializerI would like to ask if there's a workaround or a possible patch to make it compatible with Turbolinks. I believe this would greatly enhance the gem's versatility and usability for many Rails developers.
Looking forward to hearing from you soon. Thank you for your time and consideration.
The text was updated successfully, but these errors were encountered: