I had this same issue and I managed to fix it by wrapping the provider on my custom GoogleRecaptchaWrapper component, so the component will only inject the recaptcha.js after some sort of interaction happens in the page (and not on page load). Here is the code:
const RECAPTCHA_EVENT_LIST = ["mousemove", "mousedown", "keydown", "touchstart"]
export const GoogleRecaptchaWrapper = props => {
const { children } = props
const [recaptchaProps] = useState({ defer: true })
const [recaptchaNeeded, setRecaptchaNeeded] = useState(false)
const initRecaptcha = e => {
RECAPTCHA_EVENT_LIST.forEach(ev =>
document.removeEventListener(ev, initRecaptcha)
)
setRecaptchaNeeded(true)
}
ifBrowser(() => {
RECAPTCHA_EVENT_LIST.forEach(ev =>
document.addEventListener(ev, initRecaptcha)
)
})
const wrapperProps = recaptchaNeeded
? {
reCaptchaKey: AppConfig.recaptchaSiteKey,
scriptProps: recaptchaProps
}
: {}
return (
<GoogleReCaptchaProvider {...wrapperProps}>
{children}
</GoogleReCaptchaProvider>
)
}
As I say, this only injects the JS when recaptchaNeeded is true. I hope it helps!