@@ -15,6 +15,12 @@ const loadRecaptchaScript = () => new Promise((resolve, reject) => {
15
15
const recaptchaQueue = [ ]
16
16
let recaptchaPromise
17
17
let recaptchaId
18
+ const handleRecaptchaNext = async ( ) => {
19
+ if ( recaptchaQueue . length === 0 ) {
20
+ return
21
+ }
22
+ ( await loadRecaptcha ( ) ) . execute ( recaptchaId )
23
+ }
18
24
const handleRecaptchaDone = async ( code ) => {
19
25
( await loadRecaptcha ( ) ) . reset ( recaptchaId )
20
26
const { resolve } = recaptchaQueue . shift ( )
@@ -27,24 +33,14 @@ const handleRecaptchaError = async (err) => {
27
33
reject ( err )
28
34
handleRecaptchaNext ( )
29
35
}
30
- const handleRecaptchaNext = async ( ) => {
31
- if ( recaptchaQueue . length === 0 ) {
32
- return
33
- }
34
- ( await loadRecaptcha ( ) ) . execute ( recaptchaId )
35
- }
36
36
const loadRecaptcha = async ( ) => {
37
- if ( ! recaptchaPromise ) {
38
- recaptchaPromise = loadRecaptchaScript ( )
39
- }
40
- if ( ! recaptchaId ) {
41
- recaptchaId = ( await recaptchaPromise ) . render ( {
42
- theme : 'dark' ,
43
- sitekey : config . recaptcha . siteKey ,
44
- callback : handleRecaptchaDone ,
45
- 'error-callback' : handleRecaptchaError
46
- } )
47
- }
37
+ recaptchaPromise = recaptchaPromise ?? loadRecaptchaScript ( )
38
+ recaptchaId = recaptchaId ?? ( await recaptchaPromise ) . render ( {
39
+ theme : 'dark' ,
40
+ sitekey : config . recaptcha . siteKey ,
41
+ callback : handleRecaptchaDone ,
42
+ 'error-callback' : handleRecaptchaError
43
+ } )
48
44
return recaptchaPromise
49
45
}
50
46
const requestRecaptchaCode = ( ) => new Promise ( ( resolve , reject ) => {
@@ -83,7 +79,7 @@ export default (action) => {
83
79
loadRecaptcha ( )
84
80
}
85
81
} , [ recaptchaEnabled ] )
86
- const callback = useCallback ( requestRecaptchaCode , [ recaptchaEnabled ] )
82
+ const callback = useCallback ( requestRecaptchaCode , [ ] )
87
83
if ( recaptchaEnabled ) {
88
84
return callback
89
85
}
0 commit comments