reaptcha icon indicating copy to clipboard operation
reaptcha copied to clipboard

This recaptcha instance has been already rendered

Open weidonglian opened this issue 2 years ago • 16 comments

Hi @sarneeh I really like this library that does solve problems existent in other libraries, especially regarding multiple instances and react-router. This bug only exists in React >18, I have tried React 17 which works well. Repeat: https://codesandbox.io/s/jovial-cookies-uclvr5?file=/src/App.js Thanks for your attention. WD

weidonglian avatar Jun 10 '22 19:06 weidonglian

Here is what I got about the rendering failure loop. To be honest, everything seems to be working well even the below error.

index.tsx:211 Uncaught (in promise) Error: This recaptcha instance has been already rendered.
    at index.tsx:211:1
    at new Promise (<anonymous>)
    at p.r.renderExplicitly (index.tsx:210:1)
    at p.<anonymous> (index.tsx:125:1)
    at callCallback (react-dom.development.js:13122:1)
    at commitUpdateQueue (react-dom.development.js:13143:1)
    at commitLayoutEffectOnFiber (react-dom.development.js:23263:1)
    at commitLayoutMountEffects_complete (react-dom.development.js:24578:1)
    at commitLayoutEffects_begin (react-dom.development.js:24564:1)
    at commitLayoutEffects (react-dom.development.js:24502:1)

weidonglian avatar Jun 10 '22 19:06 weidonglian

Not sure what happened: The below ready's callback is triggered over and over again. setState could use the stateChange instead of changing the state ready to true. It should not trigger if the state has become ready. This could also optimize the performance.

window.grecaptcha.ready(() => {
      this.setState({ ready: true }, () => {
        if (!explicit) {
          this.renderExplicitly();
        }
        if (onLoad) {
          onLoad();
        }
      });
    });

weidonglian avatar Jun 10 '22 19:06 weidonglian

This issue manifests when <Recaptcha> is used inside of a <StrictMode> tree in React 18.

jgoz avatar Jun 13 '22 18:06 jgoz

Okay, did not realize that, in that way, it won't have any impact on a production build.

weidonglian avatar Jun 13 '22 20:06 weidonglian

@weidonglian True, but IMO it should still be fixed. StrictMode is intended to reveal potential issues, especially with future React versions/rendering modes and I think it's highlighting a legitimate problem here around side effects.

jgoz avatar Jun 13 '22 20:06 jgoz

@weidonglian True, but IMO it should still be fixed. StrictMode is intended to reveal potential issues, especially with future React versions/rendering modes and I think it's highlighting a legitimate problem here around side effects.

Absolute! Agreed, I did not mean it should not be fixed, sorry for the confusion. Just before it is fixed, it won't be a blocker, since if I ignore the console output, then it seems to be working quite well. I really want this to be fixed!

weidonglian avatar Jun 13 '22 20:06 weidonglian

Fixed in 1.12.1. Thank you @jgoz 🎉

jsardev avatar Jun 26 '22 19:06 jsardev

@sarneeh It still happens in React 18 in strict mode. I'm using 1.12.1. Also, I'm using Next.js. The error occurs when I perform a client-side navigation to a page that renders a reCAPTCHA after already having been on any page that rendered a reCAPTCHA. This isn't reproducible with strict mode disabled.

Stack trace:

Uncaught (in promise) Error: reCAPTCHA has already been rendered in this element
    at recaptcha__en.js:140:275
    at r._renderRecaptcha (index.esm.js?6a6d:1:1191)
    at eval (index.esm.js?6a6d:1:2200)
    at new Promise (<anonymous>)
    at r.renderExplicitly (index.esm.js?6a6d:1:1976)
    at p.eval (index.esm.js?6a6d:1:1122)
    at callCallback (react-dom.development.js?3c4a:13923:1)
    at commitUpdateQueue (react-dom.development.js?3c4a:13944:1)
    at commitLayoutEffectOnFiber (react-dom.development.js?3c4a:23364:1)
    at commitLayoutMountEffects_complete (react-dom.development.js?3c4a:24688:1)
    at commitLayoutEffects_begin (react-dom.development.js?3c4a:24674:1)
    at commitLayoutEffects (react-dom.development.js?3c4a:24612:1)
    at commitRootImpl (react-dom.development.js?3c4a:26823:1)
    at commitRoot (react-dom.development.js?3c4a:26682:1)
    at finishConcurrentRender (react-dom.development.js?3c4a:25981:1)
    at performConcurrentWorkOnRoot (react-dom.development.js?3c4a:25809:1)
    at workLoop (scheduler.development.js?ba31:266:1)
    at flushWork (scheduler.development.js?ba31:239:1)
    at MessagePort.performWorkUntilDeadline (scheduler.development.js?ba31:533:1)

steve-taylor avatar Jul 31 '22 10:07 steve-taylor

this issue still exists and should remain open. turning strict mode is not optimal solution

jasan-s avatar Aug 03 '22 13:08 jasan-s

@jasan-s No worries I know it still exists 😄

jsardev avatar Aug 03 '22 19:08 jsardev

Hi @sarneeh , any update on this one ? I'm facing same error on next.js

georgealexandruiancu avatar Nov 03 '22 05:11 georgealexandruiancu

Do we have a solution for this issue?

dparvanov avatar Dec 10 '22 11:12 dparvanov

Hello! Thanks for a cool wrapper around ReCAPTCHA. I'm also facing this issue and wondering if there any update on this?

seoSergio avatar Jan 27 '23 13:01 seoSergio

@sarneeh Can this ticket be marked as a bug? Would you also mind sharing what you've tried to do to fix it / why it hasn't been fixed so that one of us might have more context in order to provide support?

npearson72 avatar Apr 03 '23 19:04 npearson72

Not related to this but I had a question about invisible reaptcha. How does it work when the developer manually executes it?

Samrj12 avatar Sep 18 '23 04:09 Samrj12

any news on this?

vtrphan avatar Jan 12 '24 15:01 vtrphan