@@ -15,6 +15,12 @@ const loadRecaptchaScript = () => new Promise((resolve, reject) => {
1515const recaptchaQueue = [ ]
1616let recaptchaPromise
1717let recaptchaId
18+ const handleRecaptchaNext = async ( ) => {
19+ if ( recaptchaQueue . length === 0 ) {
20+ return
21+ }
22+ ( await loadRecaptcha ( ) ) . execute ( recaptchaId )
23+ }
1824const handleRecaptchaDone = async ( code ) => {
1925 ( await loadRecaptcha ( ) ) . reset ( recaptchaId )
2026 const { resolve } = recaptchaQueue . shift ( )
@@ -27,24 +33,14 @@ const handleRecaptchaError = async (err) => {
2733 reject ( err )
2834 handleRecaptchaNext ( )
2935}
30- const handleRecaptchaNext = async ( ) => {
31- if ( recaptchaQueue . length === 0 ) {
32- return
33- }
34- ( await loadRecaptcha ( ) ) . execute ( recaptchaId )
35- }
3636const 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+ } )
4844 return recaptchaPromise
4945}
5046const requestRecaptchaCode = ( ) => new Promise ( ( resolve , reject ) => {
@@ -83,7 +79,7 @@ export default (action) => {
8379 loadRecaptcha ( )
8480 }
8581 } , [ recaptchaEnabled ] )
86- const callback = useCallback ( requestRecaptchaCode , [ recaptchaEnabled ] )
82+ const callback = useCallback ( requestRecaptchaCode , [ ] )
8783 if ( recaptchaEnabled ) {
8884 return callback
8985 }
0 commit comments