Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This recaptcha instance has been already rendered #254

Open
weidonglian opened this issue Jun 10, 2022 · 16 comments · Fixed by #255
Open

This recaptcha instance has been already rendered #254

weidonglian opened this issue Jun 10, 2022 · 16 comments · Fixed by #255

Comments

@weidonglian
Copy link

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
Copy link
Author

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
Copy link
Author

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();
        }
      });
    });

@jgoz
Copy link
Contributor

jgoz commented Jun 13, 2022

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

@weidonglian
Copy link
Author

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

@jgoz
Copy link
Contributor

jgoz commented Jun 13, 2022

@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.

@weidonglian
Copy link
Author

@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!

jgoz added a commit to jgoz/reaptcha that referenced this issue Jun 14, 2022
jsardev added a commit that referenced this issue Jun 26, 2022
* chore(deps): bump react and styled-components

* chore: use createRoot, StrictMode in example

* fix: move timer to class field to support StrictMode

Fixes #254

* chore: fix tests with react 18

* chore: remove unused enzyme-adapter-react-16 types

Co-authored-by: Jakub Sarnowski <hello@jsarnowski.com>
@jsardev
Copy link
Owner

jsardev commented Jun 26, 2022

Fixed in 1.12.1. Thank you @jgoz 🎉

@steve-taylor
Copy link

@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)

@jasan-s
Copy link

jasan-s commented Aug 3, 2022

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

@jsardev
Copy link
Owner

jsardev commented Aug 3, 2022

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

@jsardev jsardev reopened this Aug 3, 2022
@georgealexandruiancu
Copy link

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

@dparvanov
Copy link

Do we have a solution for this issue?

@seoSergio
Copy link

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

@npearson72
Copy link

@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?

@Samrj12
Copy link

Samrj12 commented Sep 18, 2023

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

@vtrphan
Copy link

vtrphan commented Jan 12, 2024

any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.