nuxt-modules / turnstile

đŸ”Ĩ Cloudflare Turnstile integration for Nuxt
https://cloudflare.com/products/turnstile
MIT License
230 stars 18 forks source link

Callback loop with `NuxtTurnstile` #267

Closed huang-julien closed 1 year ago

huang-julien commented 1 year ago

🐛 The bug

When changing the page, the turnstile box isn't properly removed and causing and infinite loop.

to reproduce it on the reproduction,

🛠ī¸ To reproduce

https://stackblitz.com/edit/github-cuqope?file=pages%2Findex.vue,pages%2Fform.vue

🌈 Expected behaviour

we shouldn't have any warning log

ℹī¸ Additional context

I can take it, already fixed on my project :)

dargmuesli commented 1 year ago

I noticed that too, recently. If you want feel free to submit a PR! :heart:

huang-julien commented 1 year ago

sure !

iammello commented 1 year ago

Waiting for fixing.

huang-julien commented 1 year ago

Oops for those interested here's the workaround atm, within onBeforeUnmount of the compoennt wrapper NuxtTurnstile window.turnstile.remove(str) where str is the wrapper selector + div ex:

onBeforeUnmount(() => {
  window.turnstile.remove('#turnstile-wrapper div')
})

Turnstile remove function either can receive the id of the widget or if it's a selector, look for the iframe of the widget within the selector