Skip to content

Commit 5a93a95

Browse files
committed
chore: Minimal code improvements
1 parent f3d4a95 commit 5a93a95

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

packages/lib/src/lib.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ export const Turnstile = forwardRef<TurnstileInstance | undefined, TurnstileProp
192192
}
193193
}, [injectScript, turnstileLoaded, onLoadCallbackName, scriptOptions, scriptId])
194194

195-
/* if the script is injected by the user, we need to wait for turnstile to be loaded
196-
and set turnstileLoaded to true. Different from the case when handle the injection,
197-
where we set turnstileLoaded in the script.onload callback */
195+
/* Set the turnstile as loaded, in case the onload callback never runs. (e.g., when manually injecting the script without specifying the `onload` param) */
198196
useEffect(() => {
199197
if (scriptLoaded && !turnstileLoaded && window.turnstile) {
200198
setTurnstileLoaded(true)
@@ -218,11 +216,13 @@ export const Turnstile = forwardRef<TurnstileInstance | undefined, TurnstileProp
218216

219217
// re-render widget when renderConfig changes
220218
useEffect(() => {
219+
if (!window.turnstile) return
220+
221221
if (containerRef.current && widgetId) {
222222
if (checkElementExistence(widgetId)) {
223-
window.turnstile!.remove(widgetId)
223+
window.turnstile.remove(widgetId)
224224
}
225-
const newWidgetId = window.turnstile!.render(containerRef.current, renderConfig)
225+
const newWidgetId = window.turnstile.render(containerRef.current, renderConfig)
226226
setWidgetId(newWidgetId)
227227
firstRendered.current = true
228228
}

packages/lib/src/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export const injectTurnstileScript = ({
3737

3838
// Prevent duplicate script injection with the same src
3939
if (document.querySelector(`script[src="${script.src}"]`)) {
40-
console.log('Script already loaded', { scriptSrc: script.src })
4140
return
4241
}
4342

0 commit comments

Comments
 (0)