@captchafox/react
Advanced tools
Comparing version
@@ -99,2 +99,4 @@ "use client"; | ||
const executeTimeout = useRef(); | ||
const scriptErrorListener = useRef(); | ||
const hasScriptError = useRef(false); | ||
useImperativeHandle( | ||
@@ -127,2 +129,5 @@ ref, | ||
execute: () => __async(void 0, null, function* () { | ||
if (hasScriptError.current) { | ||
return Promise.reject(new RetryError()); | ||
} | ||
if (!isApiReady() || !widgetId) { | ||
@@ -149,3 +154,5 @@ return waitAndExecute(); | ||
useEffect(() => { | ||
return () => clearTimeout(executeTimeout.current); | ||
return () => { | ||
clearEvents(); | ||
}; | ||
}, []); | ||
@@ -165,3 +172,6 @@ useEffect(() => { | ||
})).catch((err) => { | ||
var _a; | ||
onError == null ? void 0 : onError(err); | ||
hasScriptError.current = true; | ||
(_a = scriptErrorListener.current) == null ? void 0 : _a.call(scriptErrorListener); | ||
console.error("[CaptchaFox] Could not load script:", err); | ||
@@ -171,4 +181,11 @@ }); | ||
}, [containerRef, sitekey, lang, mode]); | ||
const clearEvents = () => { | ||
clearTimeout(executeTimeout.current); | ||
}; | ||
const waitAndExecute = () => { | ||
return new Promise((resolve, reject) => { | ||
scriptErrorListener.current = () => { | ||
clearEvents(); | ||
reject(new RetryError()); | ||
}; | ||
executeTimeout.current = setTimeout(() => { | ||
@@ -178,3 +195,3 @@ reject(new TimeoutError("Execute timed out")); | ||
onReady.current = (id) => { | ||
clearTimeout(executeTimeout.current); | ||
clearEvents(); | ||
window.captchafox.execute(id).then(resolve).catch((error) => { | ||
@@ -181,0 +198,0 @@ const errorType = getErrorType(error); |
{ | ||
"name": "@captchafox/react", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"main": "./dist/index.cjs", | ||
@@ -5,0 +5,0 @@ "module": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
23946
4.72%528
6.88%