fix: load Turnstile without onload callback
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 78.38% (551/703)
* Lines of Code: 703
#### Quality Gates Summary
No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 80.85% (553/684)
* Lines of Code: 684
#### Quality Gates Summary
No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
All checks were successful
Tests / Backend - Tests skipped: 8, passed: 74
Backend Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 78.38% (551/703)
* Lines of Code: 703
#### Quality Gates Summary
No active quality gates.
Tests / Frontend - Lint, Tests et Build passed: 83
Frontend Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 80.85% (553/684)
* Lines of Code: 684
#### Quality Gates Summary
No active quality gates.
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
This commit is contained in:
@@ -27,7 +27,7 @@ export default function Captcha({ onToken }) {
|
|||||||
try {
|
try {
|
||||||
window.turnstile.remove(widgetIdRef.current)
|
window.turnstile.remove(widgetIdRef.current)
|
||||||
} catch {
|
} catch {
|
||||||
// Rien à faire
|
// Widget déjà supprimé
|
||||||
}
|
}
|
||||||
|
|
||||||
widgetIdRef.current = null
|
widgetIdRef.current = null
|
||||||
@@ -41,6 +41,7 @@ export default function Captcha({ onToken }) {
|
|||||||
sitekey: TURNSTILE_SITE_KEY,
|
sitekey: TURNSTILE_SITE_KEY,
|
||||||
language: 'fr',
|
language: 'fr',
|
||||||
size: 'flexible',
|
size: 'flexible',
|
||||||
|
appearance: 'always',
|
||||||
|
|
||||||
callback: (token) => {
|
callback: (token) => {
|
||||||
onToken(token)
|
onToken(token)
|
||||||
@@ -66,23 +67,28 @@ export default function Captcha({ onToken }) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const previousCallback = window.onloadTurnstileCallback
|
if (existingScript) {
|
||||||
|
existingScript.addEventListener('load', renderWidget, {
|
||||||
|
once: true,
|
||||||
|
})
|
||||||
|
|
||||||
window.onloadTurnstileCallback = () => {
|
return () => {
|
||||||
previousCallback?.()
|
cancelled = true
|
||||||
renderWidget()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!existingScript) {
|
const script = document.createElement('script')
|
||||||
const script = document.createElement('script')
|
|
||||||
|
|
||||||
script.id = TURNSTILE_SCRIPT_ID
|
script.id = TURNSTILE_SCRIPT_ID
|
||||||
script.src = `${TURNSTILE_SCRIPT_URL}&onload=onloadTurnstileCallback`
|
script.src = TURNSTILE_SCRIPT_URL
|
||||||
script.async = true
|
script.async = true
|
||||||
script.defer = true
|
script.defer = true
|
||||||
|
|
||||||
document.head.appendChild(script)
|
script.addEventListener('load', renderWidget, {
|
||||||
}
|
once: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
document.head.appendChild(script)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true
|
cancelled = true
|
||||||
@@ -94,7 +100,7 @@ export default function Captcha({ onToken }) {
|
|||||||
try {
|
try {
|
||||||
window.turnstile.remove(widgetIdRef.current)
|
window.turnstile.remove(widgetIdRef.current)
|
||||||
} catch {
|
} catch {
|
||||||
// Rien à faire
|
// Widget déjà supprimé
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user